Mutley Posted May 11, 2009 Share Posted May 11, 2009 I've fixed this error sooo many times, it must be the early morning today! Anybody see what is causing this? The SQL when printed runs fine in phpmyadmin. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource $sql="SELECT `tid`, `title`, `start_date`, `posts` FROM `ipb_tablestopics` WHERE `forum_id` = '$set_newsarea' ORDER BY `tid` DESC LIMIT $set_newslimit"; $res=mysql_query($sql); print $sql; if(mysql_num_rows($res)!=0) { while(list($tid, $title, $start_date, $posts) = mysql_fetch_row($res)){ print $title.'<br />'; print $start_date.'<br />'; print $posts.'<br />'; $resBody=mysql_query("SELECT `post` FROM `ipb_tableposts` WHERE `topic_id` = '$tid' AND `new_topic` = '1' LIMIT 1"); while($topic=mysql_fetch_array($resBody)){ print $topic["post"]; } print '<hr />'; } }else{ echo $e_norows; } Many thanks. Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/ Share on other sites More sharing options...
shadiadiph Posted May 11, 2009 Share Posted May 11, 2009 can't see anything must be something wrong in the $sql="SELECT `tid`, `title`, `start_date`, `posts` FROM `ipb_tablestopics` WHERE `forum_id` = '$set_newsarea' ORDER BY `tid` DESC LIMIT $set_newslimit"; but it does appear you are asking it do do something with num_rows if it is empty maybe its not empty maybe this !=0 should be !==0 ?? Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831452 Share on other sites More sharing options...
Mutley Posted May 11, 2009 Author Share Posted May 11, 2009 Didn't work either. I've used the same method a dozen times. Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831455 Share on other sites More sharing options...
shadiadiph Posted May 11, 2009 Share Posted May 11, 2009 have you tried to print_r $res; or print $set_newsarea jus to what they are returning Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831456 Share on other sites More sharing options...
Mutley Posted May 11, 2009 Author Share Posted May 11, 2009 Doesn't print anything. But the query is correct, it does work. Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831457 Share on other sites More sharing options...
shadiadiph Posted May 11, 2009 Share Posted May 11, 2009 $sql="SELECT `tid`, `title`, `start_date`, `posts`, `forum_id` FROM `ipb_tablestopics` WHERE `forum_id` = '$set_newsarea' ORDER BY `tid` DESC LIMIT $set_newslimit"; `forum_id` is missing Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831458 Share on other sites More sharing options...
Mutley Posted May 11, 2009 Author Share Posted May 11, 2009 Still hasn't fixed it, I'm pretty sure you don't need to select fields for the WHERE statement to work. Thanks for the help so far. Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831459 Share on other sites More sharing options...
shadiadiph Posted May 11, 2009 Share Posted May 11, 2009 maybe try it without DESC LIMIT $set_newslimit i reckon you must have a typo on fields or variables somewhere then in that statement Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831460 Share on other sites More sharing options...
Mutley Posted May 11, 2009 Author Share Posted May 11, 2009 That didn't work either. As I've said the variables in the SQL work fine, it prints the correct SQL that works in phpmyadmin - and does bring up results. So you are probably right it's a variable problem but I've tried just doing `tid` and it didn't work either. ??? Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831463 Share on other sites More sharing options...
shadiadiph Posted May 11, 2009 Share Posted May 11, 2009 i still don't get it you seem to be asking that if the value is empty then print the value which would be empty ?? Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831466 Share on other sites More sharing options...
Mutley Posted May 11, 2009 Author Share Posted May 11, 2009 The value isn't empty (or shouldn't be!) If the query returns 0 rows, it prints an error message else, it displays the rows. Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831467 Share on other sites More sharing options...
Potatis Posted May 11, 2009 Share Posted May 11, 2009 Instead of your "if" why not use while? while (mysql_num_rows($res)!=0) { //do things } Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831468 Share on other sites More sharing options...
Mutley Posted May 11, 2009 Author Share Posted May 11, 2009 Same error... Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831502 Share on other sites More sharing options...
Potatis Posted May 11, 2009 Share Posted May 11, 2009 Do any of the column names in your $sql line have the wrong spelling? Also, they are case sensitive, are they named the same in the database? Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831504 Share on other sites More sharing options...
Mutley Posted May 11, 2009 Author Share Posted May 11, 2009 Yes they are correct, as I've said it executes fine in phpmyadmin. Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831507 Share on other sites More sharing options...
PFMaBiSmAd Posted May 11, 2009 Share Posted May 11, 2009 Why not just get php/mysql to tell you why the query failed? - $res=mysql_query($sql) or die('Query failed: ' . mysql_error()); Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831508 Share on other sites More sharing options...
Potatis Posted May 11, 2009 Share Posted May 11, 2009 Yes something is not working with the query. ??? Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831510 Share on other sites More sharing options...
Ken2k7 Posted May 11, 2009 Share Posted May 11, 2009 Instead of your "if" why not use while? while (mysql_num_rows($res)!=0) { //do things } Not to put a stab at you helping others, but I'm sure that would cause an infinite loop. Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831546 Share on other sites More sharing options...
Potatis Posted May 11, 2009 Share Posted May 11, 2009 Good. That's why I asked the question, why not? Now I know why. Link to comment https://forums.phpfreaks.com/topic/157673-warning-mysql_num_rows-supplied-argument/#findComment-831942 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.