Jump to content

[SOLVED] mysql_num_rows error


Exoon

Recommended Posts

Hello,

 

Im getting an error when using this bit of code, Ive looked on php.net but can't see to find an anwser.

 

$sql = "SELECT * FROM links";
$result = mysql_query($sql) or die(mysql_error());
$num_rows = mysql_num_rows($result);

 

The error im getting is:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Link to comment
https://forums.phpfreaks.com/topic/140376-solved-mysql_num_rows-error/
Share on other sites

i swaped it over to what you said.

 

$sql = "SELECT * FROM `links` WHERE 1"
$result = mysql_query($sql) or die(mysql_error());
$num_rows = mysql_num_rows($result);

 

and i now get the following error

 

Parse error: syntax error, unexpected T_VARIABLE in update_link_hits.php on line 6

 

Line 6 is the $result = mysql line

Just as an example, the query process should always be wrapped within if statements so as to catch any errors. eg;

 

$sql = "SELECT * FROM `links` WHERE 1";
if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    // its now safe to display any data.
  } else {
    // no results found.
  }
} else {
  // your query failed.
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.