mysql_num_rows error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Trip1
Forum Newbie
Posts: 23
Joined: Sat Jan 25, 2003 7:36 pm

mysql_num_rows error

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply