$spid, 'status' => $status ); } // 获取所有记录 $sql = "SELECT * FROM list WHERE state=0"; $result = mysqli_query($con, $sql); // 定义一个空数组,用来保存查询结果 $data = array(); // 逐条取出记录,存为变量 while ($result && $row = mysqli_fetch_assoc($result)) { $id = $row['id']; $name = $row['name']; $intro = $row['jieshao']; $zhutu = $row['zhutu']; $yys = $row['yys']; $gsd = $row['gsd']; $proxy_price = $row['proxy_price']; $notes = $row['notes']; $state = 0; // 遍历 goodsta_data 数组,查找 spid 等于当前记录 id 的记录 foreach ($goodsta_data as $goodsta) { if ($goodsta['spid'] == $id) { $state = $goodsta['status'] == 1 ? $goodsta['status'] : 0; break; } } $price = $proxy_price - $portion; // 将记录存入数组中 $data[] = array( 'id' => $id, 'name' => $name, 'intro' => $intro, 'zhutu' => $zhutu, 'yys' => $yys, 'gsd' => $gsd, 'price' => $price, 'notes' => $notes, 'state' => $state ); } // 将数组转换为 JSON 格式并输出 echo json_encode($data); ?>