我的代码如下。基本上,这是一个“交易”网站(类似于groupon)。此页面显示城市中的所有活动交易,并按类别对其进行排序。例如,它将显示:“Dining”(然后是Dining下的所有交易),然后是“Adventure”(以及冒险中的所有交易)。等等。我想要做的就是缩短它。我想每个只显示最多3笔交易,但后面会显示一个链接:“在此类别中查看(x)更多”。例如:
Dining
<max of 3 deals>
(if deals > 3) "View 9 more deals in Dining"
Adventure
<max of 3 dals
(if deals > 3) "View 4 more deals in Adventure"
等。我知道我可以将它分开并拥有一堆SQL语句(在餐厅中获得所有优惠,显示3.获取冒险中的所有优惠。显示3等等。我只是想知道是否可以采用另一种方式)。< / p>
$deals = mysql_query("SELECT $db[ddd_companies].name as company_name, $db[ddd_companies].slug as company_slug, $db[ddd_deals].slug as slug, $db[ddd_deals].id, $db[ddd_deals].company_id, $db[ddd_deals].end_time, $db[ddd_deals].name, $db[ddd_deals].photo_alldeals, $db[ddd_categories].name as category
FROM $db[ddd_deals]
JOIN $db[ddd_cities_deals] as cd ON $db[ddd_deals].id=cd.deal_id
join $db[ddd_categories] on $db[ddd_categories].id=$db[ddd_deals].category_id
join $db[ddd_companies] on $db[ddd_companies].id=$db[ddd_deals].company_id
WHERE cd.city_id='$_SESSION[city_id]' AND $db[ddd_deals].start_time<='$now' AND $db[ddd_deals].end_time>'$now' AND $db[ddd_deals].deal_status_id='2' ORDER BY $db[ddd_categories].name, $db[ddd_deals].end_time");
$section = '';
while($d = mysql_fetch_array($deals)) {
if($section != $d['category']) {
// Display Section title when there is a new one
?>
<div style="clear: both;"> </div>
<h2><?php echo $d['category'];?></h2>
<?php
}
// Show deal information
$section = $d['category'];
}
编辑添加:限制允许我将结果数限制为3,但我还需要提取该类别中的数量。
答案 0 :(得分:0)