[英]how to use loop in foreach?
目前,我從discount_master表中獲取所有結果(產品ID,折扣)。 但是我想顯示product_master表中的product_name而不是產品ID,並且它們共享相同的product_id。 我關心的是如何添加一個從product_master獲取product_name的循環?
<?php
foreach($discount as $k=>$v) {
?>
<tr>
<th contenteditable="false" onBlur="saveToDatabase(this,'product_id','<?php echo $discount[$k]["d_id"]; ?>')" onClick="showEdit(this);"><?php echo $discount[$k]["product_id"]; ?></th>
<th contenteditable="true" onBlur="saveToDatabase(this,'discount','<?php echo $discount[$k]["d_id"]; ?>')" onClick="showEdit(this);"><?php echo $discount[$k]["discount"]; ?></th>
</tr>
<?php
}
?>
try this one
$qry=mysqli_query($con' SELECT discount_master.product_id,discount_master.discount, product_master.product_name,product_master.product_id,FROM discount_master LEFT JOIN product_master ON discount_master.product_id= product_master.product_id');
while ( $data=mysqli_fetch_array($qry)) {
$product_id = $data['product_id'];
$product_name=$data['product_name'];
$product_discount=$data['product_discount'];
echo $product_id." ".$product_name." ".$product_discount;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.