简体   繁体   中英

Can't get results from mySQL query to display in PHP

I am very new to PHP and can't seem to use mySQL data at all from PHP. The SQL query I wrote works fine in phpMyAdmin when I run it in the SQL editor, but the most I am able to get from the code is the following from var_dump. Nothing else displays anything at all.

resource(3) of type (mysql result)

Any help at all would be greatly appreciated!!

<?php


    ini_set(‘display_errors’,1);
    error_reporting(E_ALL|E_STRICT);

    $con = mysql_connect("localhost","XXXXXXXX","XXXXXXX");
    if (!$con) {
      die('Could not connect: ' . mysql_error());
      }

    mysql_select_db("sharetrader", $con);

    $sharelist = mysql_query("SELECT DISTINCT tblStocks.stockSymbol, tblShareData.lookupDate FROM tblStocks LEFT JOIN tblShareData ON tblShareData.tickerCode = tblStocks.stockSymbol ORDER BY tblShareData.lookupDate ASC LIMIT 0 , 30");

    if (!$sharelist) {
      die('Invalid query: ' . mysql_error());
      }

    var_dump($sharelist);

    while ($row = mysql_fetch_array($sharelist)) {
      echo $row['tblStocks.stockSymbol'];
      }

mysql_close($con);

?>

I am very new to PHP

But you're making great progress - just missing some of the finer points.

try:

while ($row = mysql_fetch_array($sharelist)) {
  var_dump($row);
}

...and it should be obvious what's happening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM