Jump to content

[SOLVED] Mysql_num_rows error


cpharry

Recommended Posts

Hi,

 

As youve probably notice im not that good with php however i know a bit.

 

mysql_select_db("wowbasec_class", $connection);

$result = mysql_query("SELECT * FROM location");
$result1 = mysql_query("SELECT * FROM char");

$rows = mysql_num_rows($result);

 

I have this at the moment but if i want to put in another count for another table in the same database how do i do that without any errors?

Link to comment
https://forums.phpfreaks.com/topic/155570-solved-mysql_num_rows-error/
Share on other sites

$rows1 = mysql_num_rows($result1);

 

And if you just need to count the rows without actually retrieving them use something like this

 

$result = mysql_query("SELECT COUNT(*) AS locationCount FROM location");
$row = mysql_fetch_array($result);
$locationCount = $row['locationCount'];

$result1 = mysql_query("SELECT COUNT(*) AS charCount FROM char");
$row1 = mysql_fetch_array($result);
$charCount = $row['charCount'];

What i want is i want to display...

 

#Locations #Characters etc.

 

But whenever i put in

 

$result2 = mysql_query("SELECT * FROM char");

$rows2 = mysql_num_rows($result2);

 

Extra i get this error...

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/wowbasec/public_html/index.php on line 10

 

char is MySQL reserved word. You shouldn't call your table like that... but if you did, use backticks around it's name

$result2 = mysql_query("SELECT * FROM `char`");

 

Here's full list of reserved words

http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

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.