Jump to content


Photo

*SOLVED* Mysql_num_rows() function error


  • Please log in to reply
2 replies to this topic

#1 meamrussian

meamrussian
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 21 April 2006 - 02:13 AM

I am building a project and learning PHP/MySQL at the same time. Here is my code:

$query = "SELECT suite, title, category, our_url FROM business ORDER BY category ASC";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);

<table width="100%">
<tr><td width="63"><u>Suite</u></td><td><u>Business</u></td><td><u>Category</u></td><td>
<u>Link</u></td></tr>
<?
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<tr><td>";
echo htmlspecialchars(stripslashes($row["suite"]));
echo "</td><td>";
echo htmlspecialchars(stripslashes($row["title"]));
echo "</td><td>";
echo htmlspecialchars(stripslashes($row["category"]));
echo "</td><td>";
echo htmlspecialchars(stripslashes($row["our_url"]));
echo "</td></tr>";
}
?>
</table>




I am getting the following error:
=====
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in my directory on line 47
=====

I have already connected to my database. I am using PHP 4.

Also, even if I try to replace mysql_num_rows($result) with "2" , I get the same errors except with mysql_fetch_array(): . Why is this happening?

Thanks.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 21 April 2006 - 02:59 AM

That error means the mysql_query is not working correctly.

Replace
<?php $result = mysql_query($query); ?>
with
<?php $result = mysql_query($query) or die('Problem with query: ' . $query . '<br />' . mysql_error()); ?>
and see if an error message appears on your screen.

Ken

#3 meamrussian

meamrussian
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 21 April 2006 - 04:11 AM

Ah, I've figured out my problem now.

Thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users