【发布时间】:2020-07-23 01:04:16
【问题描述】:
我的代码需要帮助。我想要的是显示我的数据,看起来像这种格式: 商店 |类别 |产品名称 |说明 |价格 |时间戳 |行动 样本:样本猫:样本产品:样本描述:样本标签 - 样本价格:样本时间戳:样本操作
我的查询是这样的: $get_product = $mysqli->query("SELECT b.menu_name AS store, a.category AS category, a.product AS product, a.description AS description, a.stamp AS stamp, a.id AS id, a.image作为图像来自 lfood a JOIN branch_map b ON a.menu_map = b.id WHERE a.status = 1 ".$searchQuery." ORDER BY ".$columnName." ".$columnSortOrder." LIMIT ".$row." , ".$rowperpage." ");
然后我像这样获取它们:
$data = array();
while ($row = $sms_subs->fetch_assoc()) {
$menu_id[] = $row['id'];
$image[] = $row['image'];
$store[] = $row['store'];
$category[] = $row['category'];
$product[] = $row['product'];
$description[] = $row['description'];
$stamp[] = $row['stamp'];
}
for ($i=0; $i < count($menu_id); $i++) {
$get_price = $mysqli->query("SELECT * FROM lfood_price WHERE menu_id = '".$menu_id[$i]."'");
while ($row_price = $get_price->fetch_assoc()) {
$price[] = $row_price['label'].' : '.number_format($row_price['price']);
}
$new_price = implode("<br>", $price);
$data[] = array(
"store" => $store[$i],
"category" => $category[$i],
"product" => $product[$i],
"description" => $description[$i],
"price" => $new_price,
"stamp" => date("F d Y h:i:s A", strtotime($stamp[$i])),
"actions" => "sample"
);
}
我有另一张表来存储我的产品的所有价格。结果不是它想要的, This is the actual result
在我的第二行数据中,它显示了所有价格记录,即使它不属于该 ID。我的想法是在获取价格时不恰当地使用我的 for。对于我的问题,请有人帮助/启发正确使用 for 循环。非常感谢!
【问题讨论】: