drhzn3911 2014-05-13 16:38
浏览 42

php mysql每个循环限制10个结果

i have a dropdown where there are three columns and each column contains 10 results from db i want to get first 10 result for first column, then get another 10 result for second column and so on. following is my code which generate three column but each column has all the result

<div class="mega-menu">
            <?php
                $query = mysql_query("select * from product where pid = 0 and status=1") or die(mysql_error());
                $total_rows = ceil(mysql_num_rows($query)/10);
                for($i=1; $i<=$total_rows; $i++)
                {
            ?>
              <div class="col-1">
                <ol>
                    <?php
                        $first_result = mysql_query("select * from product where pid = 0 and status=1 limit 10 offset 10") or die(mysql_error());
                        if(mysql_num_rows($first_result) > 0)
                        { 
                            while($first_row = mysql_fetch_array($first_result)) { 
                    ?>
                    <li><a href="<?=base_url().$first_row['product_slug']?>"><?=$first_row['product_name']?></a></li>
                    <?php } }?>
                </ol>
              </div>
              <?php  } ?>
        </div>

i know i am doing mistake in first result query

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害