Here is a snip of my code and although the mysql connection work and even the $num calcullate the numrows work as the tables gets created unfortunately no data gets populated, can any one one advise.

1 - mysql_connect (OK)
2 - mysql_select_db (OK)
3 - mysql_numrows (OK)
4 - table gets created based on $max even but no data get populated, please help.

All this goes inside a html page!

  include 'config.php';

                                @mysql_select_db($database) or die('Could not connect: ' . mysql_error());
                                $query="SELECT name,correct,wrong,percentage,level,date FROM stats ORDER BY correct DESC LIMIT $max";

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



                                <table border="1" cellspacing="2" cellpadding="2">
                                <td><font face="Arial, Helvetica, sans-serif">Name</font></td>
                                <td><font face="Arial, Helvetica, sans-serif">Correct</font></td>
                                <td><font face="Arial, Helvetica, sans-serif">Wrong</font></td>
                                <td><font face="Arial, Helvetica, sans-serif">Percent</font></td>
                                <td><font face="Arial, Helvetica, sans-serif">Level</font></td>
                                <td><font face="Arial, Helvetica, sans-serif">Date</font></td>

                                while ($i < $num) {



                                <td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
                                <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
                                <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td>
                                <td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td>
                                <td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td>
                                <td><font face="Arial, Helvetica, sans-serif"><?php echo $f6; ?></font></td>

4 Years
Discussion Span
Last Post by adam.adamski.96155

$num=mysql_numrows($result) is wrong, it should be:

How strange that the script tests that $query exists (which is a string that is defined the previous line), then sends the query to the DB without any error checking:


Hi Adam,

Thank you for your reply and advice, I have corrected the spelling mistake mysql_num_rows, I still need to assign it to a varible to $num as I use it in the loop while

($i < $num) {}

Main issue still remains where the output of the query is not being assigned to my varibles and populating the fileds.

I still looking ofr additional help :-)


The $num returns the correct number of rows, that does not seem to be the problem, the issue seems to me that I am just not getting any fields / columns from my query and i don't understand as it all looks perfectly fine.


I'm not familiar with this syntax:
I would do it a bit differently:

<!--use a table class rather than repeat font face declaration every line-->
<table class="table" border="1" cellspacing="2" cellpadding="2">

// You don't need to run a while loop depending on num_results,
// just use while(mysql_fetch_array), will stop when no more results.

$sql = "SELECT * FROM tablename";
if(!$result = mysql_query($sql)){// put all DB operations inside error check loop
    die('Invalid query: ' . mysql_error());
if(!mysql_num_rows($result) > 0){// using num_rows to make sure there are results to display.
    die("no results, aborting...");

while($row = mysql_fetch_assoc($result)){
    echo "<tr><td>".$row['name']."</td>"; //<tr> on the first row
    echo "<td>".$row['correct']."</td>";
    echo "<td>".$row['wrong']."</td>";
    echo "<td>".$row['percentage']."</td>";
    echo "<td>".$row['level']."</td>";
    echo "<td>".$row['date']."</td></tr>"; //close </tr> on last row.

My Man, you are spot on, this worked as a treat and does exacly what I wanted. I still don't know why my loop did not work :-P, anyway, many thanks for all your help

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.