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 11 of 11
  1. #1
    New Coder
    Join Date
    Sep 2009
    Location
    uk
    Posts
    83
    Thanks
    4
    Thanked 3 Times in 3 Posts

    mysql_fetch_array() expects parameter 1 to be resource, boolean given in

    hi . i have an error i can not get rid of. what i have done is copied a search function to enable me to search for something else. . theres one line giving me trouble and i dont know how to fix it.
    PHP Code:
    ///////////////////////////////////////search for smilies
    else if($action=="searchsm")

    {

        
    addonline(getuid_sid($sid),"Searching For Smilies","");

        echo 
    "<head>";

        echo 
    "<title>Search</title>";

        echo 
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";

        echo 
    "</head>";

        echo 
    "<body>";

        echo 
    "<p>";
      echo 
    "<form action=\"smiliesearch.php?action=find&amp;sid=$sid\" method=\"post\">";

        echo 
    "Nickname: <input name=\"stext\" maxlength=\"15\"/><br/>";

        echo 
    "Order: <select name=\"cat\">";

        echo 
    "<option value=\"1\">general</option>";

        echo 
    "<option value=\"2\">Personal</option>";

        echo 
    "<option value=\"3\">Adult smilies</option>";

        echo 
    "</select><br/>";

        echo 
    "<input type=\"Submit\" name=\"send\" value=\"Find It\"></form>";
        

      echo 
    "<p align=\"center\">";

      echo 
    "<b>9 </b><a accesskey=\"9\" href=\"index.php?action=search&amp;sid=$sid\"><img src=\"../phpThumb/phpThumb.php?src=../images/search.gif\" alt=\"\"/>Search Menu</a><br/>";

      echo 
    "<b>0 </b><a accesskey=\"0\" href=\"index.php?action=main&amp;sid=$sid\"><img src=\"../phpThumb/phpThumb.php?src=../images/home.gif\" alt=\"\"/>Home</a>";  echo "</p></body>";

      echo 
    "</p></body>";

    }

    else if(
    $action=="find")
    {
        
        
    addonline(getuid_sid($sid),"Searching For smilies","");
       echo 
    "<head>";
        echo 
    "<title>Search</title>";
       echo 
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";
        echo 
    "</head>";
        echo 
    "<body>";
        echo 
    "<p>";
       {
          
             if(
    $page=="" || $page<1)$page=1;
                
    $where_table "dave_smilies";
            
    $cond "scode";
            
    $select_fields "id, scode";
            if(
    $sor=="1")
            {
              
    $ord_fields "scode";
              }
           
    $noi mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ".$where_table." WHERE ".$cond." LIKE '%".$stext."%'"));
           
    $num_items $noi[0];
            
    $items_per_page 5;
           
    $num_pages ceil($num_items/$items_per_page);
     if((
    $page>$num_pages)&&$page!=1)$page$num_pages;
       
    $limit_start = ($page-1)*$items_per_page;
       
    $sql "SELECT ".$select_fields." FROM ".$where_table." WHERE ".$cond." LIKE '%".$stext."%' ORDER BY ".$ord_fields." LIMIT $limit_start, $items_per_page";
            
    $items mysql_query($sql);
           while(
    $item=mysql_fetch_array($items))
           {
              
                  echo 
    parsepm ($item[1], $sid);
                  echo 
    "$item[1]<br/>";
               
         }
          echo 
    "<p align=\"center\">";
          if(
    $page>1)
        {
          
    $ppage $page-1;
          echo 
    "<a href=\"smiliesearch.php?action=find&amp;page=$ppage&amp;sid=$sid&amp;view=$view\">«PREV</a> ";
        }
        if(
    $page<$num_pages)
        {
          
    $npage $page+1;
          echo 
    "<a href=\"smiliesearch.php?action=find&amp;page=$npage&amp;sid=$sid&amp;view=$view\">Next»</a>";
        }
        echo 
    "<br/>$page/$num_pages<br/>";
        if(
    $num_pages>2)
        {
            
    $rets "<form action=\"smiliesearch.phpaction=$action&amp;sid=$sid&amp;page=$(pg)\" method=\"get\">";
            
    $rets .= "<input name=\"page\" style=\"-wap-input-format: '*N'\" size=\"2\"/>";
            
    $rets .= "<input type=\"hidden\" name=\"action\" value=\"$action\"/>";
            
    $rets .= "<input type=\"hidden\" name=\"sid\" value=\"$sid\"/>";
            
    $rets .= "<input type=\"submit\" value=\"Go To Page\"/>";
            
    $rets .= "</form>";
       echo 
    $rets;
        }
        

        echo 
    "</p>";

            }

        

    echo 
    "</p>";

      echo 
    "<p align=\"center\">";

      echo 
    "<b>9 </b><a accesskey=\"9\" href=\"index.php?action=search&amp;sid=$sid\"><img src=\"../phpThumb/phpThumb.php?src=../images/search.gif\" alt=\"\"/>Search Menu</a><br/>";

      echo 
    "<b>0 </b><a accesskey=\"0\" href=\"index.php?action=main&amp;sid=$sid\"><img src=\"../phpThumb/phpThumb.php?src=../images/home.gif\" alt=\"\"/>Home</a>";

      echo 
    "</p></body>";


    the line thats giving me the error is

    while($item=mysql_fetch_array($items))

    hope someone can help .

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Echo out your $sql variable, and use mysql_error() to track down any errors.

  • #3
    New Coder
    Join Date
    Sep 2009
    Location
    uk
    Posts
    83
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by bdl View Post
    Echo out your $sql variable, and use mysql_error() to track down any errors.
    sorry but how do i do that ?

  • #4
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Change this line:

    PHP Code:
    $items mysql_query($sql); 
    to

    PHP Code:
    $items mysql_query($sql) or die(mysql_error()); 

  • #5
    New Coder
    Join Date
    Sep 2009
    Location
    uk
    Posts
    83
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by bcarl314 View Post
    Change this line:

    PHP Code:
    $items mysql_query($sql); 
    to

    PHP Code:
    $items mysql_query($sql) or die(mysql_error()); 
    i get this error now

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 5' at line 1

  • #6
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Try this:

    PHP Code:
    $items mysql_query($sql) or die($sql." -- ".mysql_error()); 

  • #7
    New Coder
    Join Date
    Sep 2009
    Location
    uk
    Posts
    83
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by bcarl314 View Post
    Try this:

    PHP Code:
    $items mysql_query($sql) or die($sql." -- ".mysql_error()); 
    done that and this is wot i get now

    SELECT id, scode FROM dave_smilies WHERE scode LIKE '%%' ORDER BY LIMIT 0, 5 -- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 5' at line 1

  • #8
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    SELECT id, scode FROM dave_smilies WHERE scode LIKE '%%' ORDER BY LIMIT 0, 5
    Isn't that obvious? Where's the value of $ord_fields?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #9
    New Coder
    Join Date
    Sep 2009
    Location
    uk
    Posts
    83
    Thanks
    4
    Thanked 3 Times in 3 Posts
    PHP Code:
    $cond "scode";
            
    $select_fields "id, scode";
            if(
    $sor=="1")
            {
              
    $ord_fields "scode";
              } 
    i know theres prob an easier way of coding this. am no coder .i copy and paste stuff that does similiar things then edit the tables etc etc till i get it right.

    the above code was was search function for a member and all i have done is edit the table names and fields to match where i want to search .

    this is my table i want to search
    `id` int(100) NOT NULL AUTO_INCREMENT,
    `scode` varchar(15) NOT NULL DEFAULT '',
    `imgsrc` varchar(200) NOT NULL DEFAULT '',
    `hidden` char(1) NOT NULL DEFAULT '0',
    `cat` int(10) NOT NULL DEFAULT '1',

    really i only want to display the scode and the actual image which is parsed using

    PHP Code:
    echo parsepm ($item[1], $sid);
                  echo 
    "$item[1]<br/>"
    i have done a few more adjustments with the above comment and i dont get errors now now it dosnt display what i want it to display. in other words its showing the same 5 images no matter what i search for. and no next page prev page stuff.

    sorry

  • #10
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    if($sor=="1")
    {
    $ord_fields = "scode";
    }
    The variable $ord_fields will get a value only if $sor=="1". You may need to assign a default value in the else part or before that if
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #11
    New Coder
    Join Date
    Sep 2009
    Location
    uk
    Posts
    83
    Thanks
    4
    Thanked 3 Times in 3 Posts
    sorted it at last. one thing tho . i have a catorgory for each type of smilie and each catorgory has a number.

    i have included a drop down box but dont no how to get it so it selects the correct catorgory .

    PHP Code:
    ///////////////////////////////////////search for smilies
    else if($action=="searchsm")

    {

        
    addonline(getuid_sid($sid),"smilies search","");

        echo 
    "<head>";

        echo 
    "<title>Search</title>";

        echo 
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";

        echo 
    "</head>";

        echo 
    "<body>";

        echo 
    "<p>";

        echo 
    "<form action=\"smiliesearch.php?action=find&amp;sid=$sid\" method=\"post\">";

        echo 
    "Smilie Code: <input name=\"stext\" maxlength=\"15\"/><br/>";

        echo 
    "Order: <select name=\"cat\">";

        echo 
    "<option value=\"1\">general</option>";

        echo 
    "<option value=\"2\">personal</option>";

        echo 
    "<option value=\"3\">Adult</option>";

        echo 
    "</select><br/>";

        echo 
    "<input type=\"Submit\" name=\"send\" value=\"Find It\"></form>";

        echo 
    "</p>";

      echo 
    "<p align=\"center\">";

      echo 
    "<b>9 </b><a accesskey=\"9\" href=\"index.php?action=search&amp;sid=$sid\"><img src=\"../phpThumb/phpThumb.php?src=../images/search.gif\" alt=\"\"/>Search Menu</a><br/>";

      echo 
    "<b>0 </b><a accesskey=\"0\" href=\"index.php?action=main&amp;sid=$sid\"><img src=\"../phpThumb/phpThumb.php?src=../images/home.gif\" alt=\"\"/>Home</a>";  echo "</p></body>";

      echo 
    "</p></body>";

    }
    //////////////////////////////////////////

    else if($action=="find")

    {

      
    $stext $_POST["stext"];
      
    $scode $_POST["scode"];
      
    $sin $_POST["sin"];

      
    $cat $_POST["cat"];

        
    addonline(getuid_sid($sid),"smilie search","");

        echo 
    "<head>";

        echo 
    "<title>Search</title>";

        echo 
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";

        echo 
    "</head>";

        echo 
    "<body>";

        echo 
    "<p>";



        

            if(
    trim($stext)=="")

            {

                echo 
    "<br/>Failed to search for club";

            }else{

              
    //begin search

              
    if($page=="" || $page<1)$page=1;

              

                
    $where_table "dave_smilies";

                
    $cond "scode";

                
    $select_fields "id, scode, cat";

                if(
    $cat=="1")

                {

                  
    $ord_fields "name";

                }else if(
    $cat=="2"){

                    
    $ord_fields "lastact DESC";

                }else if(
    $cat=="3"){

                    
    $ord_fields "regdate";

                }

              

              
    $noi mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ".$where_table." WHERE ".$cond." LIKE '%".$stext."%'"));

              
    $num_items $noi[0];

              
    $items_per_page 10;

              
    $num_pages ceil($num_items/$items_per_page);

        if((
    $page>$num_pages)&&$page!=1)$page$num_pages;

        
    $limit_start = ($page-1)*$items_per_page;



        
    $sql "SELECT ".$select_fields." FROM ".$where_table." WHERE ".$cond." LIKE '%".$stext."%' ORDER BY scode LIMIT $limit_start, $items_per_page";

              
    $items mysql_query($sql);

              while(
    $item=mysql_fetch_array($items))

              {

                  
    //$tlink = "<a href=\"index.php?action=viewuser&amp;sid=$sid&amp;who=$item[0]\">".htmlspecialchars($item[1])."</a><br/>";
                  // echo  $tlink;
                   
    echo parsepm ($item[1], $sid);
                   echo 
    "$item[1]<br/>";


              }

              echo 
    "<p align=\"center\">";

              if(
    $page>1)

        {

          
    $ppage $page-1;

            
    $rets "<form action=\"search.php?action=$action&amp;sid=$sid&amp;page=$ppage\" method=\"post\">";

          
    $rets .= "<input type=\"hidden\" name=\"stext\" value=\"$stext\"/>";

          
    $rets .= "<input type=\"hidden\" name=\"sin\" value=\"$sin\"/>";

          
    $rets .= "<input type=\"hidden\" name=\"sor\" value=\"$sor\"/>";

            
    $rets .= "<input type=\"Submit\" name=\"Prev\" value=\"Prev\"></form>";



            echo 
    $rets;

        }

        if(
    $page<$num_pages)

        {

          
    $npage $page+1;

            
    $rets "<form action=\"smiliesearch.php?action=find&amp;sid=$sid&amp;page=$npage\" method=\"post\">";

          
    $rets .= "<input type=\"hidden\" name=\"stext\" value=\"$stext\"/>";

          
    $rets .= "<input type=\"hidden\" name=\"sin\" value=\"$sin\"/>";

          
    $rets .= "<input type=\"hidden\" name=\"sor\" value=\"$sor\"/>";

            
    $rets .= "<input type=\"Submit\" name=\"Next\" value=\"Next\"></form>";



            echo 
    $rets;

        }

        echo 
    "<br/>$page/$num_pages<br/>";

        if(
    $num_pages>2)

        {

            
    $rets "<form action=\"smiliesearch.php?action=find&amp;sid=$sid&amp;page=$(pg)\" method=\"post\">";

            
    $rets .= "<input name=\"pg\" style=\"-wap-input-format: '*N'\" size=\"3\"/>";

          
    $rets .= "<input type=\"hidden\" name=\"stext\" value=\"$stext\"/>";

          
    $rets .= "<input type=\"hidden\" name=\"sin\" value=\"$sin\"/>";

          
    $rets .= "<input type=\"hidden\" name=\"sor\" value=\"$sor\"/>";

            
    $rets .= "<input type=\"Submit\" name=\"Send\" value=\"Go To Page\"></form>";



            echo 
    $rets;

        }

        echo 
    "</p>";

            }

        

    echo 
    "</p>";

      echo 
    "<p align=\"center\">";

      echo 
    "<b>9 </b><a accesskey=\"9\" href=\"index.php?action=search&amp;sid=$sid\"><img src=\"../phpThumb/phpThumb.php?src=../images/search.gif\" alt=\"\"/>Search Menu</a><br/>";

      echo 
    "<b>0 </b><a accesskey=\"0\" href=\"index.php?action=main&amp;sid=$sid\"><img src=\"../phpThumb/phpThumb.php?src=../images/home.gif\" alt=\"\"/>Home</a>";

      echo 
    "</p></body>";




  •  

    Posting Permissions

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