douhe4608 2014-12-28 19:25
浏览 6
已采纳

<br>每隔4个结果来自sql

Simple question of course But I still could not figure it till now :) Im pulling names out of an sql and I want to be like 1 2 3 4,then next Line like 5, 6, 7, 8 Like So

<a>Bob</a>, <a>John</a>, <a>Bob</a>, <a>John</a> <BR>
<a>Bob</a>, <a>Ion</a>, <a>Bob</a>, <a>Pon</a> <BR>

Well thats What I want it To look like But For Now Its One Row Endless with no spaces is what I acheved so far Like So :)

<?PHP
require('connect.php');
$sql="SELECT  * FROM profile";
  $result=mysql_query($sql);
  while($row=mysql_fetch_array($result)){
        $name =$row['username'];
        $power =$row['power'];
?>
<a href="user.php?id=<?PHP echo $name; ?>"><span class='user-group-<?PHP echo $power; ?>'><?PHP echo $name; ?></span> </a>,


<?PHP } ?>  

Now What Do I need to do to have every forth result + that
space :?

  • 写回答

1条回答 默认 最新

  • duanraa1984 2014-12-28 20:15
    关注

    Use an $i counter:

        require('connect.php');
        $sql    =   "select * from profile";
        $result =   mysql_query($sql);
    
        // Start at 1
        $i = 1;
        while($row = mysql_fetch_array($result)){
            $name   =   $row['username'];
            $power  =   $row['power']; ?>
    <a href="user.php?id=<?PHP echo $name; ?>"><span class='user-group-<?php echo $power; ?>'><?PHP echo $name; ?></span> </a>
         <?php  
                // When hit 4, add <br />
                if($i == 4) {
                        echo '<br />';
                        // Reset to 0. $i will then auto-increment
                        // to 1 when hits $i++
                        $i = 0;
                    }
                else
                    // Add comma if not equal to 4.
                    echo ',';
                $i++;
            }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化