My Question related to arrays
$Parray=[1,2];
Table Structure:-
BrandName BrandType PostID
sss top 1
fsdds top 1
sr bottom 2
My Query Is:-
for($i=0;$i<sizeof($Parray);$i++){
$sql=mysql_query("SELECT BrandName,BrandPeople from BrandDetails where PostID='Parray[$i]'");
while($row=mysql_fetch_assoc($sql)){
$out[]=$row;
}
}
print json_encode($out);
my out is:- [{"BrandName":"sss","BrandType":"top"},{"BrandName":"fsdds","BrandType":"top"},{"BrandName":"sr","BrandType":"bottom"}]
BUT I NEED tow diffrent arrays for different postids:- {[{"BrandName":"sss","BrandType":"top"},{"BrandName":"fsdds","BrandType":"top"}],[{"BrandName":"sr","BrandType":"bottom"}]}
How to put mysql queries into different arrays
Moderator: General Moderators
Re: How to put mysql queries into different arrays
As long as the outer {}s are supposed to be []s,
then use two arrays: one for the end result like the $out you have now, and another for just the items you get from each query.
Code: Select all
[[{"BrandName":"sss","BrandType":"top"},{"BrandName":"fsdds","BrandType":"top"}],[{"BrandName":"sr","BrandType":"bottom"}]]Code: Select all
$out=array(); // initialize your variables!
for($i=0;$i<sizeof($Parray);$i++){
$sql=mysql_query("SELECT BrandName,BrandPeople from BrandDetails where PostID='Parray[$i]'");
$rows=array();
while($row=mysql_fetch_assoc($sql)){
$rows[]=$row;
}
$out[]=$rows;
}
Re: How to put mysql queries into different arrays
Thanks requinix