douti0687 2015-10-03 09:35
浏览 23
已采纳

如何显示MySQL表中的内容,因为行数等于3的多个[关闭]

I have a MySQL table having many rows and my question is,

How to

i) Display rows from MySQL table as the row length is equal to multiples of 3

ii) In other case if row count not equal to multiples of 3 then display the row equal to nearest multiples of 3 for example, if the row length is 5 then display only first 3 rows.

for more clarification,

  1. If mysql_num_rows = 3, display all three rows.
  2. If mysql_num_rows = 5, display any three rows.
  3. If mysql_num_rows = 11, display any nine rows.
  • 写回答

2条回答 默认 最新

  • dpli36193 2015-10-03 10:14
    关注

    Use

       $res=mysqli_query(
    $con,"SELECT * FROM tbl_name");
     $row=mysqli_num_rows($res);//calculating total row count
    
    $lim=$row-$row%3;//deciding limit
    $res1=mysqli_query(
    $con,"SELECT * FROM tbl_name LIMIT $lim");
    //echo '<br>'.$row1=mysqli_num_rows($res1);
    while($show=mysqli_fetch_array($res1))
    {
        echo '<br>'.$show['id'];
    }
    

    Execute the query & show your data

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集