Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2009
    Location
    UK
    Posts
    90
    Thanks
    14
    Thanked 0 Times in 0 Posts

    PHP Warning Error relating to a MYSQL Query, Basic Help needed, Pls

    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

    Code:
    $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

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,132
    Thanks
    12
    Thanked 332 Times in 328 Posts
    the SQL query fails, and then mysql_query() returns false, which is not the parameter type mysql_num_rows() expects.

    can be avoided by
    PHP Code:
    $result mysql_query($query) or die(mysql_error()); 
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    This code

    PHP Code:
    $numrows=mysql_numrows($result2); 
    needs to be changed to this one

    PHP Code:
    $numrows=mysql_num_rows($result2); 
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •