Unholy Prayer Posted November 30, 2006 Share Posted November 30, 2006 Ok, this is my code to get the number of threads in the forum:[code]$count_sql = mysql_query('SELECT * FROM threads WHERE $fid = fid');$threads = mysql_num_rows($count_sql);[/code]This is the error message that i get:[quote]Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mtechdev/public_html/bbultimate/index.php on line 41[/quote]Can someone tell me what is wrong with my code? Link to comment https://forums.phpfreaks.com/topic/28933-mysql_num_rows-not-a-valid-mysql-result-resource/ Share on other sites More sharing options...
fert Posted November 30, 2006 Share Posted November 30, 2006 $count sql should be $count_sql Link to comment https://forums.phpfreaks.com/topic/28933-mysql_num_rows-not-a-valid-mysql-result-resource/#findComment-132484 Share on other sites More sharing options...
Unholy Prayer Posted November 30, 2006 Author Share Posted November 30, 2006 It is... Link to comment https://forums.phpfreaks.com/topic/28933-mysql_num_rows-not-a-valid-mysql-result-resource/#findComment-132488 Share on other sites More sharing options...
fert Posted November 30, 2006 Share Posted November 30, 2006 try this[code]$count_sql = mysql_query('SELECT * FROM threads WHERE $fid = fid') or die(mysql_error());[/code] Link to comment https://forums.phpfreaks.com/topic/28933-mysql_num_rows-not-a-valid-mysql-result-resource/#findComment-132490 Share on other sites More sharing options...
jsladek Posted November 30, 2006 Share Posted November 30, 2006 print out the $count_sql I'm sure there is a problem there'SELECT * FROM threads WHERE $fid = fid'should the $fid = fid be fid = $fid ????-John Link to comment https://forums.phpfreaks.com/topic/28933-mysql_num_rows-not-a-valid-mysql-result-resource/#findComment-132491 Share on other sites More sharing options...
Unholy Prayer Posted November 30, 2006 Author Share Posted November 30, 2006 Fert, I tried yours, but I get this message when I refreshed my page: Unknown column '$fid' in 'where clause'jsladek: i already tried that before I posted this and it didn't do anything. Link to comment https://forums.phpfreaks.com/topic/28933-mysql_num_rows-not-a-valid-mysql-result-resource/#findComment-132493 Share on other sites More sharing options...
fert Posted November 30, 2006 Share Posted November 30, 2006 where there's your problem Link to comment https://forums.phpfreaks.com/topic/28933-mysql_num_rows-not-a-valid-mysql-result-resource/#findComment-132495 Share on other sites More sharing options...
Unholy Prayer Posted November 30, 2006 Author Share Posted November 30, 2006 I don't know how to fix it... this is my entire page of coding:[code]<?phpinclude('styles/default/page_header.tpl');require_once('config.php');//Let's start the category selection.$getcats = mysql_query("select * from categories");while($r=mysql_fetch_array($getcats)){ $id=$r["id"]; $name=$r["name"]; $description=$r["description"]; echo "<table align='center' width='95%' cellspacing='1' cellpadding='1' style='background-color: #000000;'> <td align='center' colspan='4' class='bgcat'><p align='left'><b>$name</b>- $description</p></td> </tr> <tr> <td class='cellnames' width='50%'>Forum Name</td> <td class='cellnames' width='15%'>Threads</td> <td class='cellnames' width='15$'>Replies</td> <td class='cellnames' width='20%'>Latest Post</td> </tr><tr>";//Now we display the forums for the selected category.$getforums = mysql_query("select * from forums where cid = $id order by fid");while($r=mysql_fetch_array($getforums)){ $fid=$r["fid"]; $forumname=$r["forumname"]; $fdescription=$r["description"]; $cid=$r["cid"]; //How many threads are there in the displayed forum?$count_sql = mysql_query('SELECT * FROM threads WHERE fid = $fid') or die(mysql_error());$threads = mysql_num_rows($count_sql); echo "<tr> <td align='left' class='forumrow' width='50%'><a href='viewforum.php?id=$fid'>$forumname</a><br>$fdescription</td> <td class='forumrow' width='15%'>$threads</td> <td class='forumrow' width='15%'>0</td> <td class='forumrow' width='20%'>Not Available</td> </tr>"; } echo "</table>"; } ?>[/code] Link to comment https://forums.phpfreaks.com/topic/28933-mysql_num_rows-not-a-valid-mysql-result-resource/#findComment-132497 Share on other sites More sharing options...
jsladek Posted November 30, 2006 Share Posted November 30, 2006 do this...//How many threads are there in the displayed forum?$count_sql = mysql_query('SELECT * FROM threads WHERE fid = $fid') or die(mysql_error());print("<hr>SQL:$count_sql<hr> "):#$threads = mysql_num_rows($count_sql);Add that pring statement and comment out the line that is crashing the program and see what the sql looks like-John Link to comment https://forums.phpfreaks.com/topic/28933-mysql_num_rows-not-a-valid-mysql-result-resource/#findComment-132503 Share on other sites More sharing options...
bljepp69 Posted November 30, 2006 Share Posted November 30, 2006 This line:[code]$count_sql = mysql_query('SELECT * FROM threads WHERE fid = $fid') or die(mysql_error());[/code]uses single quotes. The variable won't be processed in single quotes. Change it to:[code]$count_sql = mysql_query("SELECT * FROM threads WHERE fid = $fid") or die(mysql_error());[/code] Link to comment https://forums.phpfreaks.com/topic/28933-mysql_num_rows-not-a-valid-mysql-result-resource/#findComment-132558 Share on other sites More sharing options...
boo_lolly Posted November 30, 2006 Share Posted November 30, 2006 what you should REALLY do is this...[code]$count_sql = mysql_query("SELECT * FROM threads WHERE fid = '". $fid ."'") or die(mysql_error());[/code]take note of the single quotes wrapped around the double quotes wrapped around $fid. Link to comment https://forums.phpfreaks.com/topic/28933-mysql_num_rows-not-a-valid-mysql-result-resource/#findComment-132781 Share on other sites More sharing options...
chipk1 Posted November 30, 2006 Share Posted November 30, 2006 [quote author=Unholy Prayer link=topic=116788.msg476025#msg476025 date=1164849356]Ok, this is my code to get the number of threads in the forum:[code]$count_sql = mysql_query('SELECT * FROM threads WHERE $fid = fid');$threads = mysql_num_rows($count_sql);[/code]This is the error message that i get:[quote]Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mtechdev/public_html/bbultimate/index.php on line 41[/quote]Can someone tell me what is wrong with my code?[/quote]Had the same problem yesterday. Try this $count_sql = mysql_query("SELECT * FROM threads WHERE fid = '$fid'") or die(mysql_error());Change single ' to double ' and the put single ' around $fid like this '$fid'should work than Link to comment https://forums.phpfreaks.com/topic/28933-mysql_num_rows-not-a-valid-mysql-result-resource/#findComment-132986 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.