$aUsers[]=$row["item_name"]."<a href='cart.php'>Add to cart</a>";
dear friends it show the same code as written ....
I want show
item name and add to cart link ..plz help
array showing do not showing required result
Moderator: General Moderators
-
khalidhabib.cs
- Forum Newbie
- Posts: 14
- Joined: Tue Jul 17, 2012 1:35 am
Re: array showing do not showing required result
Show us the code that displays the array $aUsers.
-
khalidhabib.cs
- Forum Newbie
- Posts: 14
- Joined: Tue Jul 17, 2012 1:35 am
Re: array showing do not showing required result
Code: Select all
sql="SELECT item_name,item_price,item_id FROM items ORDER BY item_id";
$query=mysql_query($sql);
/*
*/
$aUsers = array();
$aInfo = array();
while($row=mysql_fetch_array($query)){
$a=$row["item_name"].".|Rs".$row["item_price"].".";
$aUsers[]=$a;
$aInfo = $row["item_price"];
}
$input = strtolower( $_GET['input'] );
$len = strlen($input);
$aResults = array();
if ($len)
{
for ($i=0;$i<count($aUsers);$i++)
{
// had to use utf_decode, here
// not necessary if the results are coming from mysql
//
if (strtolower(substr(utf8_decode($aUsers[$i]),0,$len)) == $input)
$aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) );
//if (stripos(utf8_decode($aUsers[$i]), $input) !== false)
// $aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) );
}
}
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
if (isset($_REQUEST['json']))
{
header("Content-Type: application/json");
echo "{\"results\": [";
$arr = array();
for ($i=0;$i<count($aResults);$i++)
{
$arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"\"}";
}
echo implode(", ", $arr);
echo "]}";
}
else
{
header("Content-Type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?><results>";
for ($i=0;$i<count($aResults);$i++)
{
echo "<rs id=\"".$aResults[$i]['id']."\" info=\"".$aResults[$i]['info']."\">".$aResults[$i]['value']."</rs>";
}
echo "</results>";
}
?>
Last edited by Benjamin on Thu Aug 16, 2012 4:16 am, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.