duanmu0834 2015-11-08 18:02
浏览 88
已采纳

在MySQL结果之间插入HTML代码

I want to insert a html code in between MySQL results.

My query

if($sql = $mysqli->query("SELECT * FROM  table Limit 20")){

    $row = mysqli_fetch_array($sql);

//Results display here    

    $sql->close();


}else{

     printf("There seems to be an issue. Please Trey again");;

}

Above query is pulling 20 results at a time. I want to insert <div class="block"></div>after pulling 3rd result and continue other results after that div (using a single query)

Can anyone point me how to do this.

  • 写回答

1条回答 默认 最新

  • dongze5043 2015-11-08 18:34
    关注

    As it simple as it gets. You just have to count each iteration and when it reaches 3 you print out the div element.

    <?php
    $mysqli = new mysqli("localhost","","","");
    
    if ($mysqli->connect_errno){
        echo "Failed to connect to MySQL";
    }
    
    if ($result = $mysqli->query("SELECT * FROM table")) {
        $counter = 0;
    
        while ($row = $result->fetch_assoc()) {
    
            echo $row["______"];
    
            if((++$counter) == 3) {
                echo '<div class="block"></div>';
            }       
        }
    
        $result->close();
    }
    
    $mysqli->close();
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 经gamit解算的cors站数据再经globk网平差得到的坐标做形变分析
  • ¥15 GD32 SPI通信时我从机原样返回收到的数据怎么弄?
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!