我正面临问题编号范围或价格范围。
product_id starts_at price
1815 1 5.95
1815 36 5.62
1815 96 5.00
SELECT *
FROM price_tiers
WHERE product_id = '$productid' AND store_type='W'
ORDER BY `starts_at` ASC
我想要展示
1 to 35 = 5.95
36 to 95 = 5.62
96 to more = 5.00
我的代码
<?php
$price_tiers = mysql_query("SELECT *
FROM price_tiers
WHERE product_id = '$productid'
AND store_type='W'
ORDER BY `starts_at` ASC ")
or die (mysql_error());
while ($myrow = mysql_fetch_assoc($price_tiers))
{
echo $starts_at = $myrow['starts_at'].
" to " . "$".
$product_price = $myrow['price'].
"<br>";
}
?>
非常感谢您的帮助。
答案 0 :(得分:1)
你需要这样的东西:
$current = mysql_fetch_assoc($price_tiers);
do {
$next = mysql_fetch_assoc($price_tiers);
echo $current['starts_at'];
echo " to ";
echo $next['starts_at'] - 1;
echo $current['price'];
$current = $next;
while ($next !== false);
这不会完美地按原样运作,但应该让你开始。
答案 1 :(得分:0)