Page 1 of 1

array showing do not showing required result

Posted: Wed Aug 15, 2012 2:43 am
by khalidhabib.cs
$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

Re: array showing do not showing required result

Posted: Wed Aug 15, 2012 1:29 pm
by califdon
Show us the code that displays the array $aUsers.

Re: array showing do not showing required result

Posted: Thu Aug 16, 2012 12:03 am
by khalidhabib.cs

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>";
	}
?>