這是我的代碼PHP的循環問題
$rQuery="SELECT * FROM rowManagr WHERE id=0";
$rResult = $mysqli->query($rQuery)or die($mysqli->error.__LINE__);
while($row = $rResult->fetch_assoc())
{
$rowQuery='SELECT * FROM row_vid WHERE rowid='.$row['rowid'];
$rowResult = $mysqli->query($rowQuery)or die($mysqli->error.__LINE__);
while($rowHome = $rowResult->fetch_assoc())
{
if($rowHome['showid']!=0)
{
$json[] = array(....);
}
elseif($rowHome['season_id']!=0){
$json[] = array(....);
}
elseif($rowHome['showid']==0 && $rowHome['season_id']==0){
$json[] = array(....);
}
}
$jsondata[$row['rowname']]=$json;
$g['responses']= $jsondata;
}
$jsons = json_encode($g);
echo $jsons;
這段代碼的輸出是(例如)
{"responses":{
"Seasons":[
{"1a"},
{"2a"},
{"3a"},
{"4a"}
],
"Other Show":[
{"1a"},
{"2a"},
{"3a"},
{"4a"},
{"1b"},
{"2b"},
{"3b"},
{"4b"}
],
"Videos":[
{"1a"},
{"2a"},
{"3a"},
{"4a"},
{"1b"},
{"2b"},
{"3b"},
{"4b"},
{"1a"},
{"2a"},
{"3a"},
{"4a"},
{"1c"},
{"2c"},
{"3c"},
{"4c"}
]
} }
季節,其他顯示,視頻中包含4results但在輸出將季節複製到其他節目中,並將其他節目複製到視頻中。
實際產量應該是
{
"responses":{
"Seasons":[
{"1a"},
{"2a"},
{"3a"},
{"4a"}
],
"Other Show":[
{"4a"},
{"1b"},
{"2b"},
{"3b"},
{"4b"}
],
"Videos":[
{"1c"},
{"2c"},
{"3c"},
{"4c"}
]
}
}
感謝
請你的代碼剝離下來到相關配件! – urzeit
你能解釋我們這是什麼意思'我的問題是響應。季節,響應。其他顯示和響應。視頻顯示包括4結果,但在輸出響應。季節被複制到響應。其他顯示和響應。季節,響應。 OtherShow被複制到response.Video' ?? – Roopendra
strip down ..... – user3294288