doudizhu2222 2016-05-08 06:04
浏览 37

如何按变量自定义值对结果进行排序

I have the following if statement. I want to sort by a variable called $slippercent variable if $slippercent is between 2.5 and 4 show in top and the rest next.

Let say i have the following records:

record A = `$slippercent`=1
record B = `$slippercent`=2.6
record C = `$slippercent`=2.5
record D = `$slippercent`=2.0
record E = `$slippercent`=5
record F = `$slippercent`=4
record G = `$slippercent`=2.8
record H = `$slippercent`=3

I want to show as follows

record C
record B
record G
record H
record F

the rest orders dont matter

 $record = mysqli_query($con,"SELECT * FROM tbl ORDER BY (Tread_Design='$rtdesign') DESC, (Manufacturer='$rbrand') DESC,Brand_Name");
   while ($row = mysqli_fetch_array($record)) {
  if (preg_match("/\b".preg_quote($txtbrand)."\b/i", $row['Brand_Name']) && ($row['OD']>=$small && $row['OD']<=$large) && ($txtbrand != "" && $row['OD'] != "" && $row['Brand_Name']!="") ) 

{   
$frontrc= $row['RC'];
$slippercent = round(((($frontrc*$it2t1)/$rearrc)-1)*100,2);
$slippercent2 = round(((($frontrc*$it2t1)/$rearrc)-1)*2000, 2);

echo "<td style='width:60px;  text-align:left; vertical-align: middle;'>";echo $row['SW'];"</td>"; 
echo "<td style='width:60px; text-align:left;vertical-align: middle;'>";echo $row['OD'];"</td>";
echo "<td id='slippercent' style='width:80px;  text-align:center;'><center>";echo$slippercent;echo'%';"</center></td>";

 }

I want to sort or Order if $slippercent is between 2.5 and 4 to show on top any order after

  • 写回答

2条回答 默认 最新

  • donglinxin8765 2016-05-08 06:49
    关注

    Use this:

    ORDER BY slipercent BETWEEN 2.5 AND 4 DESC, slipercent ASC
    

    Booleans are treated as false = 0, true = 1, and you can use that in an ORDER BY clause.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c