需求如下:
添加租房详情页面右侧的您可能感兴趣的房源。规则为:当前房源的价格梯度为筛选条件,梯度分为1000以下,1000-2000、2000-3000、3000-5000、5000以上。
例如当前详情页面的租房价格为1000,则筛选1000至2000的房源,若为2135,则筛选条件为2000-3000等等,筛选的条数为10条。
这个业务逻辑该怎么写啊???
这个逻辑,你似乎写个if语句就可以了吧
我怎么写不对啊
$tags=$db->query("select price from aijiacms_rent_7");
while($r=$db->fetch_array($tags)){
$mon=$r['price'];
if($mon<=1000){
$price=$db->query("select * from aijiacms_rent_7 where price<=1000 limit 0,10");
while($t=$db->fetch_array($price)){
$prices[]=$t;
}
break;
}
}
是能调用出但是价格不对啊
if判断一下就好了吧
这个就用if应该可以啦
我知道是判断 但是达不到的语气的效果啊
$tags=$db->query("select * from aijiacms_rent_7");
while($r=$db->fetch_array($tags)){
$mon=$r['price'];
switch($mon){
case $mon $price=$db->query("select * from aijiacms_rent_7 where price<=1000 limit 0,10");
while($t=$db->fetch_array($price)){
$prices[]=$t;
}
break;
case 1000<$mon && $mon<=2000:
$price=$db->query("select * from aijiacms_rent_7 where price>1000 and price<=2000 limit 0,10");
while($t=$db->fetch_array($price)){
$prices[]=$t;
}
break;
case 2000<$mon && $mon<=3000:
$price=$db->query("select * from aijiacms_rent_7 where price>2000 and price<=3000 limit 0,10");
while($t=$db->fetch_array($price)){
$prices[]=$t;
}
break;
case 3000<$mon && $mon<=4000:
$price=$db->query("select * from aijiacms_rent_7 where price>3000 and price<=4000 limit 0,10");
while($t=$db->fetch_array($price)){
$prices[]=$t;
}
break;
case 4000<$mon && $mon<=5000:
$price=$db->query("select * from aijiacms_rent_7 where price>4000 and price<=5000 limit 0,10");
while($t=$db->fetch_array($price)){
$prices[]=$t;
}
break;
case 5000<$mon:
$price=$db->query("select * from aijiacms_rent_7 where price>5000 limit 0,10");
while($t=$db->fetch_array($price)){
$prices[]=$t;
}
break;
}
}求大神写一个让小弟我看看 或者是帮小弟我看看 哪里有错的改改
你的第一个case就断掉了吧,好像没写条件
$tags=$db->query("select price from aijiacms_rent_7");
while($r=$db->fetch_array($tags)){
$mon=$r['price'];
if($mon<=1000){
$price=$db->query("select * from aijiacms_rent_7 where price<=1000 limit 0,10");
while($t=$db->fetch_array($price)){
$prices[]=$t;
}
break;
}
}
提供一个思路看看可行否:
拿到价格 x
y=x/1000 (取整的那个)
然后一次if判断,if y>5 执行语句一(高价格),else 执行语句二 (将变量放在代码中)
这样代码行能少点吧
int current = getCurrentPrice()
ifelse判断值在那个区间不就可以了?
current > 1000 && current < 2000
select * from tablename where tablename.price > 1000 and tablename.price <2000
current > 2000 && current < 4000
select * from tablename where tablename.price > 2000 and tablename.price <4000