Page 1 of 1

mysql_num_rows error

Posted: Sun Sep 07, 2003 8:47 am
by Trip1
http://lasalas.net/irc/codepaste/view.php?cp_id=166
-------------------------------------------------------------

On line 35, im trying to find out how many albums the user currently has, by using mysql_num_rows on a query that selects id from albums where username= the persons username. I can echo out the query, and input it directly into mysql, and it will select the correct values in the table, however i get an error when i try to do mysql_num_rows.

There is multiple entries for the username i am trying, so thats not the problem.

There's alot of extra stuff in the code atm, please just ignore it(exists part)



Thanks in advance for any help

Posted: Sun Sep 07, 2003 9:45 am
by volka
try

Code: Select all

$result = mysql_query("SELECT id FROM albums WHERE username='$username'");
$countrows = mysql_num_rows($result) or die(mysql_error());
Maybe there is some kind of error, then mysql will tell you.
btw: what is the error you get?

Posted: Sun Sep 07, 2003 12:57 pm
by m3rajk
note: volka's code misses one needed thing. assuming the connection is in a variable $db, it dhoulf have mysql_error($db) in place of mysql_error

Posted: Mon Sep 08, 2003 5:32 am
by twigletmac
m3rajk wrote:note: volka's code misses one needed thing. assuming the connection is in a variable $db, it dhoulf have mysql_error($db) in place of mysql_error
Unless you are using multiple database connections, there is no need to specify which to use in mysql_error() as the last one opened (and for most people this is the only one open) will be used.

Mac