PDA

View Full Version : mysql_num_rows(): ERROR


mob4u1
02-11-2008, 12:28 PM
Can anyone help? i have this code and it doesn't seem to work, i keep getting the error:

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

<?php

$failure='<li><strong><a href="#" target="_blank">ERROR...</a></strong></li>';

$query = 'SELECT users.username, date_format(pages.pubdate, "%d %b %Y") FROM users, pages where published=\'1\' ORDER BY pages.pubdate DESC LIMIT 0, 5';
@ $newest = mysql_query($query);
if( mysql_error() )
{ print($failure); }
$ile = mysql_num_rows($newest);

for($i=1; $i<=10 && $i<=$ile; $i++)
{
$wiersz=mysql_fetch_row($newest);
print('<li><span style="text-transform: capitalize;"><strong><a href="'.$URL.$wiersz[0].'" target="_blank">'.$wiersz[0].'</span><font size="1"> - ('.$wiersz[1].')</font></a></strong></li>');
}
?>

abduraooft
02-11-2008, 12:39 PM
Change @ $newest = mysql_query($query); to
$newest = mysql_query($query) or die(mysql_error()); to see any errors in query.

Andrew Johnson
02-11-2008, 04:41 PM
Try this rewrite:


<?php
$failure='<li><strong><a href="#" target="_blank">ERROR...</a></strong></li>';

$query = 'SELECT users.username, date_format(pages.pubdate, "%d %b %Y") FROM users, pages where published=\'1\' ORDER BY pages.pubdate DESC LIMIT 0, 5';
$newest = mysql_query($query) or print(mysql_error());

$ile = mysql_num_rows($newest);

for($i=1; $i<=10 && $i<=$ile; $i++)
{
$wiersz=mysql_fetch_row($newest);
print('<li><span style="text-transform: capitalize;"><strong><a href="'.$URL.$wiersz[0].'" target="_blank">'.$wiersz[0].'</span><font size="1"> - ('.$wiersz[1].')</font></a></strong></li>');
}
?>

mob4u1
02-12-2008, 06:57 PM
thanks for the help...

have now figured it out and changed the code to include another file that connect to the DB

mysql_connect($dbHost, $dbUsername, $dbPassword, $dbName);
mysql_select_db($dbName);