目前我从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
}
?>
答案 0 :(得分:0)
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;
}