FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Mysql Error





DanielXP
I keep getting this error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in userstats.php on line 9

this is the code

Code:
$totallinks = mysql_query("select * from links where by = '$logged[username]'");
$totallinks = mysql_num_rows($totallinks);


The sql table is links and the field in it is by

I want it to find how many $logged[username] links has posted.

I tryed and tryed again for a long time and can't get thi to work
Deathplanter
First make sure it IS valid resource-maybe something wrong with syntax?
$totallinks = mysql_query("select * from links where by = '$logged[username]'");
echo(mysql_error());
$totallinks = mysql_num_rows($totallinks);

BTW,shouldn't query be like this?
$totallinks = mysql_query("SELECT * FROM `links` where `by` = ".$logged[username]);
DanielXP
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 'by = 'Leo'' at line 1
mathiaus
try using
Code:
$totallinks = mysql_query("SELECT * FROM `links` WHERE `by` = '".$logged[username]."'");
DanielXP
with that it displays

Resource id #10
Stubru Freak
DanielXP wrote:
with that it displays

Resource id #10


Also use the mysql_count_rows too of course.
But better (more effective) would be:

$totallinks = mysql_query("SELECT COUNT(1) FROM `links` WHERE `by` = '".$logged[username]."'");
$totallinks = mysql_fetch_row($totallinks);
$totallinks = $totallinks[0];
DanielXP
Of corse Rolling Eyes


Works Thanks Stubru Freak!
Related topics
Mysql error!
MySql error: Column count doesn't match value count at row 1
MySQL error
MySQL error
MySQL error 1604
[solved] Weird mysql error
Suppressing mysql error
[mySQL] Error I cannot Debug
Error connecting to mysql ; please help
Mysql error: Warning: mysql_num_rows():
mysql error
Urgent! MySQL error!
MYSQL Ajax im Installation Error
Mysql ERROR
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.