1 回答

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超10個(gè)贊
它既簡(jiǎn)單又簡(jiǎn)單,您不需要在 while 循環(huán)內(nèi)使用 for 循環(huán)。請(qǐng)使用以下代碼,希望對(duì)您有所幫助。
$sql = "SELECT * FROM cart WHERE sess_id = '$sess_id'";
$result = mysqli_query($conn, $sql);
$items= array();
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$items[] = "{sku: "."'".$row["prod_sku"]."'".", quantity : ".$row["prod_qty"]."}, <br>";
}
}
// to print the array use the following command
// print_r($items);
// to echo the $items variable, you may encode it by json
echo json_encode($items);
謝謝。
- 1 回答
- 0 關(guān)注
- 181 瀏覽
添加回答
舉報(bào)