...

View Full Version : mysql_fetch_array() expects parameter 1 to be resource, boolean given in



nclemale
04-02-2010, 12:42 AM
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.


///////////////////////////////////////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\">&#171;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&#187;</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 .

bdl
04-02-2010, 12:51 AM
Echo out your $sql variable, and use mysql_error() to track down any errors.

nclemale
04-02-2010, 12:58 AM
Echo out your $sql variable, and use mysql_error() to track down any errors.

sorry but how do i do that ?

bcarl314
04-02-2010, 01:35 AM
Change this line:



$items = mysql_query($sql);


to



$items = mysql_query($sql) or die(mysql_error());

nclemale
04-02-2010, 01:43 AM
Change this line:



$items = mysql_query($sql);


to



$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

bcarl314
04-02-2010, 02:31 AM
Try this:



$items = mysql_query($sql) or die($sql." -- ".mysql_error());

nclemale
04-02-2010, 01:26 PM
Try this:



$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

abduraooft
04-02-2010, 03:17 PM
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?

nclemale
04-02-2010, 03:39 PM
$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



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

abduraooft
04-02-2010, 04:07 PM
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

nclemale
04-02-2010, 08:50 PM
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 .



///////////////////////////////////////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>";

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum