Displaying one result instead of two in a "simple" mysql query

The following query yields two results instead of one, how can I fix this? If you have any more hints they are welcom, thx

$link = mysql_connect("$mysqlhost", "$mysqluser", "$mysqlpass")
  or die ("Could not connect to MySQL");

mysql_select_db ($mysqldbase)
  or die ("Could not select database");

  //SELECT * FROM `filedownloads` WHERE filename='{$filename}'")
 $sql = 'SELECT downloads FROM `filedownloads` WHERE id = 1 LIMIT 0, 30 ';
 $result = mysql_query ($sql);

// printing HTML result

print "<table>\n";
while ($line = mysql_fetch_array($result)) {
  print "\t<tr>\n";
  while(list($col_name, $col_value) = each($line)) {
    print "\t\t<td>$col_value</td>\n";
  }
  print "\t</tr>\n";
}
print "</table>\n";

  mysql_close($link);
PeterdeBAsked:
Who is Participating?
 
nizsmoDeveloperCommented:
Normally I use echo, so I have changed your prints to echos, but there should be no difference. Apparently echos give a slight performance advantage as they say, I'm not sure.
Is your inner while loop necessary? how bout something like this?



$link = mysql_connect("$mysqlhost", "$mysqluser", "$mysqlpass")
  or die ("Could not connect to MySQL");

mysql_select_db ($mysqldbase)
  or die ("Could not select database");

  //SELECT * FROM `filedownloads` WHERE filename='{$filename}'")
 $sql = 'SELECT downloads FROM `filedownloads` WHERE id = 1 LIMIT 0, 30 ';
 $result = mysql_query ($sql);

// printing HTML result

echo "<table>\n";
while ($line = mysql_fetch_array($result)) {
  echo "\t<tr>\n";
  echo $line[0];
  echo "\t</tr>\n";
}
echo "</table>\n";

  mysql_close($link);
0
 
jericotolentinoCommented:
nizsmo's solution is actually simpler, but should you still like to use print, here's something you can just add to it. I've included the <td></td> tags in the script below.
--------------------
$link = mysql_connect("$mysqlhost", "$mysqluser", "$mysqlpass") or die ("Could not connect to MySQL");

mysql_select_db ($mysqldbase) or die ("Could not select database");

//SELECT * FROM `filedownloads` WHERE filename='{$filename}'")
 $sql = 'SELECT downloads FROM `filedownloads` WHERE id = 1 LIMIT 0, 30 ';
 $result = mysql_query ($sql);

// printing HTML result

print "<table>\n";
while ($line = mysql_fetch_array($result)) {
  print "<tr>";
  print "\t\t<td>".$line['downloads']."</td>\n";
  print "\t</tr>\n";
}
print "</table>\n";

mysql_close($link);
0
 
MasonWolfCommented:
Change this:
 $sql = 'SELECT downloads FROM `filedownloads` WHERE id = 1 LIMIT 0, 30 ';

To this:
 $sql = 'SELECT downloads FROM `filedownloads` WHERE id = 1 LIMIT 0, 1';
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
PeterdeBAuthor Commented:
nizsmo: thank you, you have made an end to many hours of hard thinking
0
 
PeterdeBAuthor Commented:
jericotolentino: thank you too for your help it is greatly appreciated
0
 
PeterdeBAuthor Commented:
MasonWolf: wow, thank you very much too
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.