PDA

View Full Version : PHP Warning Error relating to a MYSQL Query, Basic Help needed, Pls



mobimad
03-05-2010, 11:18 AM
Hi Everyone,
I keep getting this error in my error_log within my server for a MYSQL query that i'm using on a page. The pages pull the data fro DB and displays it fine but i keep getting these errors, and would like to clean it up. if anyone can see what i s wrong that would be great.

Error:
PHP Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/blahblah/public_html/domain.com/tags.php on line 66



$page = ($_SERVER['REQUEST_URI']);
$table= "table1";
$site= "site1";
$keyword = $_GET['search'];
?>

<div>All stuff Tagged With <? echo"$keyword" ?><br />
</div>
<br/>

<?


if(!isset($start)) $start = 0;

if ($keyword <> ""){

require ('connect/globals.php');
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");


$query="SELECT * FROM $table WHERE info LIKE '%$keyword%' ORDER BY id ASC LIMIT $start , 3";
$query2="SELECT * FROM $table WHERE info LIKE '%$keyword%' ORDER BY id ASC ";


$result=mysql_query($query);
$result2=mysql_query($query2);
LINE 66 $num=mysql_numrows($result);
$numrows=mysql_numrows($result2);

if ($numrows == 0)
{

echo "Sorry , nothing found";
echo "<br />";

}



$i=0;
while ($i < $num) {
$dls=mysql_result($result,$i,"downloads");
$pic=mysql_result($result,$i,"thumb");
$picbig=mysql_result($result,$i,"thumbbig");
$fileID=mysql_result($result,$i,"id");
$info=mysql_result($result,$i,"info");
$desc=mysql_result($result,$i,"description");
$udesc = urlencode($desc);
$filename=mysql_result($result,$i,"filename");
$ListName=mysql_result($result,$i,"dispname");
$firstPart = 'http://domain.com/download.php?';
$unencodedP = "id=$fileID&table=$table&page=$page&site=$site";
$urlToUse = $firstPart . '&amp;p=' . urlencode($unencodedP);
$rawurl = str_replace(' ', '%20', $url);


echo "<img src='thumb/$picbig' alt='test' width='120' height='120'/><a href='$urlToUse&amp;ct=$udesc'><img src='../images/button.gif' alt='test' width='40' height='30'/></a><br/><div class='subtext3'><a href='$urlToUse&amp;ct=$udesc+Video'>$desc <br/></a></div><div class='linebreak'></div>";


Thankyou in-advance
Jenna

Dormilich
03-05-2010, 11:24 AM
the SQL query fails, and then mysql_query() returns false, which is not the parameter type mysql_num_rows() expects.

can be avoided by

$result = mysql_query($query) or die(mysql_error());

masterofollies
03-05-2010, 07:49 PM
This code


$numrows=mysql_numrows($result2);


needs to be changed to this one


$numrows=mysql_num_rows($result2);

Fou-Lu
03-05-2010, 08:21 PM
Yes, that should be updated to mysql_num_rows; however, it should be noted that mysql_numrows does actually exist. Its been retained for all that 10+ish year old code to allow backwards compatibility. So yeah, its been deprecated for like, 10 years now O.o
The error itself indicates that the query has failed.