我对此感到很困惑。在使用下面的开关/案例时,如果我回显案例 1,我的结果如下:
Metal Cover (300)
Plexi (300)
Flat Cover (200)
Paper Cover (250)
当我回显 json_encode 时,它返回以下内容:
{"300":"Plexi (300)","200":"Flat Cover (200)","250":"Paper Cover (250)"}
为什么我失去了我的一排?- 谢谢
代码
$type = 'cover';
$stt = 1;
$productId = 81;
$results = array();
switch ($type) {
case "cover":
$query = mysql_query("SELECT *
FROM albumcover
WHERE productId = '{$productId}'
");
$results[0] ="None";
switch ($stt){
case 1:
while($row = mysql_fetch_array($query)){
echo $results[$row['price2']] = $row['coverupgrade'] . ' (' . $row['price2'] . ')<br>';
}
break;
case 2:
while($row = mysql_fetch_array($query)){
$results[$row['price3']] = $row['coverupgrade'] .' (' . $row['price3'] . ')';
}
break;
case 3:
while($row = mysql_fetch_array($query)){
$results[$row['price4']] = $row['coverupgrade'] .' (' . $row['price4'] . ')';
}
break;
default :
while($row = mysql_fetch_array($query)){
$results[$row['price1']] = $row['coverupgrade'].' ('.$row['price1'].')';
}
break;
}
echo json_encode($results);