Jump to content

mysql_num_rows... not a valid MySQL result resource?


Unholy Prayer

Recommended Posts

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
Share on other sites

I don't know how to fix it... this is my entire page of coding:

[code]<?php
include('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
Share on other sites

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
Share on other sites

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
Share on other sites

[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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.