gpt4 book ai didi

php - 如何在连接表时计算行数

转载 作者:行者123 更新时间:2023-11-29 21:11:12 25 4
gpt4 key购买 nike

我有两张表,一张用于显示销售点详细信息和位置,一张用于显示没有。该特定商店的报价,我想加入两个表来显示商店及其各自的报价和位置,我通过加入表成功获取了商店及其报价,但我想知道如何计算数量。特定地点的优惠信息。我用于连接表的 sql 查询是

$sql_2="SELECT p.id,p.outlet_id,p.offer_title,p.original_price,
p.discount,p.discount_price,p.offer_image,p.offer_details,
o.outlet_id,o.outlet_title,o.outlet_locality,o.segment_type
FROM products as p,outlets as o
WHERE p.outlet_id=o.outlet_id AND o.segment_type='$category'
GROUP BY o.outlet_locality ";

从上面我可以获取地区组,我想计算总报价,即。 ALL() 和每个地点的单独地点优惠我的 html 是 '

<h3>Location</h3>
<ul class="offer-location" >
<li class="checkbox">
<label>
<input type="checkbox" class="i-check">All <small>(657)</small>
</label>
</li>
<?php
foreach($qry_2 as $v2){
?>
<li class="checkbox">
<label>
<input type="checkbox" class="i-check"/>
<?php echo $v2['outlet_locality'] ?> <small>(120)</small>
</label>
</li>
<?php
}
?>
</ul>

最佳答案

 $sql_2="SELECT p.id,p.outlet_id,p.offer_title,p.original_price,
p.discount,p.discount_price,p.offer_image,p.offer_details,
o.outlet_id,o.outlet_title,o.outlet_locality,o.segment_type, count(p.outlet_id) as outletCount
FROM products as p,outlets as o
WHERE p.outlet_id=o.outlet_id AND o.segment_type='$category'
GROUP BY o.outlet_locality ";

关于php - 如何在连接表时计算行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36349926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com