Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql_fetch_array returns nothing while mysql_num_rows returns 4 in php
    text
    copied!<p>I have some code in php that accesses a mysql database in sorted order, then prints out the info in a table. However, whenever it calls mysql_fetch_array, the function returns nothing, even though mysql_num_rows is 4. That is, if I do $row=mysql_fetch_array($result);, $row['name'] is "" even though there is most certainly a name column in the table. A snippet of the code is below:</p> <pre><code>&lt;?php include_once("include.php"); $number=0; if(!isset($_GET['scores'])) { $number=10; } else if((int )$_GET['scores']&gt;100) { $number=100; } else if((int) $_GET['scores']&lt;0) { $number=10; } else { $number=(int) $_GET['scores']; } $con=mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname, $con); $result=mysql_query("SELECT * FROM ".$dbtable_scores." ORDER BY score DESC,date;", $con); $num=1; echo("&lt;table&gt;"); echo("&lt;tr&gt;&lt;td&gt;position&lt;/td&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;score&lt;/td&gt;&lt;td&gt;date&lt;/td&gt;&lt;/tr&gt;"); while($row=mysql_fetch_array($result) &amp;&amp; $num&lt;=$number) { echo("&lt;tr&gt;"); echo("&lt;td&gt;".$num."&lt;/td&gt;"); echo("&lt;td&gt;".$row['name']."&lt;/td&gt;&lt;td&gt;".$row['score']."&lt;/td&gt;&lt;td&gt;".$row['date']."&lt;/td&gt;"); echo("&lt;/tr&gt;"); $num++; } echo("&lt;/table&gt;"); mysql_close($con); ?&gt; </code></pre> <p>I have checked the query in mysql cli, and it seems to work fine. However, as you will see if you go to <a href="http://mtgames.org/index.php" rel="nofollow">http://mtgames.org/index.php</a>, the table has only the numbers that are not generated from mysql. The mysql table has columns name, score, date, among others. Any help is appreciated. Thanks, -Michael.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload