My if statements are only adding one element to the arrays even though they should add several as several have identical tags.
<?php
include("mysqlconnect.php");
$select_query = "SELECT `ImagesId`,`ImagesPath`,`Tag` FROM `offerstbl` ORDER by `ImagesId` DESC";
$sql = mysql_query($select_query) or die(mysql_error());
$data = array();
while($rows = mysql_fetch_array($sql,MYSQL_BOTH)){
if ($rows['Tag'] == "sport"){
$data['sport'] = array($rows['ImagesId'], $rows['ImagesPath'], $rows['Tag']);
}
if ($rows['Tag'] == "food"){
$data['food'] = array($rows['ImagesId'], $rows['ImagesPath'], $rows['Tag']);
}
if ($rows['Tag'] == "clothes"){
$data['clothes'] = array($rows['ImagesId'], $rows['ImagesPath'], $rows['Tag']);
}
}
echo json_encode($data);
?>
switch,case,breakto make it neater perhaps?$data = array();, but that won't matter. What do you mean one element, one element as in one array? Please make clear. I'm guessing you need to do this:$data[]['sport'] =. You probably need a multidimensional array.