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 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)