If you want the value
of key
['category']
of the associative array $emparray
to be assigned as predefined data
instead of the fetched result $row['tag']
at the 6th, 11th, 17th place and so on, the below code would give you the desired result.
$i=1;
while($row=mysql_fetch_array($result)){
if(($i%6)==0){
$emparray['category'] = "PREDEFINED DATA";
}
else{
//Data from the database
$emparray['category'] = ucwords($row["tag"]);
}
array_push($json_response,$emparray);
$i++;
}
If you want to add predefined data
to the 6th, 11th, 17th place, and push the 6th fetched result $row['tag']
to the 7th place, you should do it like this.
$i=1;
while($row=mysql_fetch_array($result)){
if(($i%6)==0){
$emparray['category'] = "PREDEFINED DATA";
array_push($json_response,$emparray);
$i++;
}
//Data from the database
$emparray['category'] = ucwords($row["tag"]);
array_push($json_response,$emparray);
$i++;
}
If you want predefined data
to be added at the 6th, 11th, 17th place, in addition to the 6th, 11th, 17th value of the fetched result $row["tag"]
, you are approaching this wrongly as you can't assign two values to a key, you would need to make $emparray['category']
a subarray i.e. $emparray['category'][]
instead or concatenate the two before assigning it to the key.