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? Quote Link to comment Share on other sites More sharing options...
fert Posted November 30, 2006 Share Posted November 30, 2006 $count sql should be $count_sql Quote Link to comment Share on other sites More sharing options...
Unholy Prayer Posted November 30, 2006 Author Share Posted November 30, 2006 It is... Quote Link to comment 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] Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
fert Posted November 30, 2006 Share Posted November 30, 2006 where there's your problem Quote Link to comment 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] Quote Link to comment 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 Quote Link to comment 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] Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.