By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,089 Members | 2,301 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,089 IT Pros & Developers. It's quick & easy.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

P: 2
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\tockholes\includes\menu.inc.php on line 9

<div class="left">
<div class="menu">
<div class="boxhead" style="text-align:center;"> <strong>Menu</strong> </div>
<br />
<?php
require ('includes/db_conn.inc.php');
$query = "select * from menu order by item_order";
$result = mysql_query($query);
$num_results = mysql_num_rows($result); <--- HERE!
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<tr>
<td align="left" nowrap="nowrap">';
if (($row['sub']) == 'no') {
echo '<a href="';
echo ($row['url']);
echo '">';
echo ($row['name']);
echo '</a>';
}
else {
echo '- <a style="font-size:11px" href="';
echo ($row['url']);
echo '">';
echo ($row['name']);
echo '</a>';
}
echo '</td></tr>';
}
?>
</div>


Please help. I keep getting that error message.

Code previously worked, and now isn't. Racking my brains, and can't seem to find a fault.

Thanks

Pete
Jan 8 '07 #1
Share this Question
Share on Google+
3 Replies


ronverdonk
Expert 2.5K+
P: 4,258
Warning: you must enclose your code within the appropriate php, code or html tags! Please read the Posting Guidelines at the top of this forum before you post anything again.

To answer your question: you better find out first whether the SELECT generated an error, so change you mysql_query to the following and see what error message it throws.[php]$result = mysql_query($query)
or die ("SELECT error: ".mysql_error());
[/php]
Ronald :cool:
Jan 8 '07 #2

khalidbaloch
P: 61
this might be syntax error ,add die mysql_error() function in every
mysql_query ,to figure out the mistake

you should also add this mysql_connect and dl_select in db_conn_ini.php
this code might

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //load the db_conn_ini file
  3. require ('includes/db_conn.inc.php');
  4. $query = "select * from menu order by item_order";
  5. $result = mysql_query($query) OR die(mysql_error());
  6. $num_results = mysql_num_rows($result) OR die(mysql_error());  // 
  7. while ($row = mysql_fetch_array($result))
  8. while ($row = mysql_fetch_array($result))
  9. {
  10. echo '<tr>
  11. <td align="left" nowrap="nowrap">';
  12.  if ($row['sub'] == 'no') {
  13. echo '<a href="',$row['url'],$row['name'],'"</a>'; 
  14. }
  15. else {
  16. echo '- <a style="font-size:11px" href="',$row['url'],$row['name'],'</a>';          
  17. }
  18.  
  19. echo '</td></tr>';
  20. ?>
the code for db_conn_ini.php

Expand|Select|Wrap|Line Numbers
  1. <?
  2. // SET MYSQL INFORMATION
  3. $db_host = "localhost";
  4. $database = "database";
  5. $db_user = "root";
  6. $db_pass = "dbpasswd";
  7.  
  8. // CONNECT TO MYSQL DATABASE
  9. $db = mysql_connect($db_host, $db_user, $db_pass) OR die(mysql_error()) ;
  10. mysql_select_db("$database") Or die(mysql_error());
  11. ?>
  12.  
i made some changes to code so that it look better and i hope this will help you
Jan 8 '07 #3

P: 2
Thank you for your help, all working now!
Jan 9 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.