Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让PHP在引导网格中的5项之后插入一个新的div_Php_Twitter Bootstrap - Fatal编程技术网

如何让PHP在引导网格中的5项之后插入一个新的div

如何让PHP在引导网格中的5项之后插入一个新的div,php,twitter-bootstrap,Php,Twitter Bootstrap,好的,我在一个页面上显示25个项目,但是当我这样做的时候,它破坏了引导网格系统。如何让PHP在写入5项后创建一个新的div 主要PHP代码: if(isset($_GET['span'])){ echo "3"; $grp = $_GET['span']; if($grp==1){ $getGames = "SELECT * FROM tbl_games WHERE tbl_games.games_id < 6";

好的,我在一个页面上显示25个项目,但是当我这样做的时候,它破坏了引导网格系统。如何让PHP在写入5项后创建一个新的div

主要PHP代码:

if(isset($_GET['span'])){
        echo "3";
        $grp = $_GET['span'];
        if($grp==1){
            $getGames = "SELECT * FROM tbl_games WHERE tbl_games.games_id < 6";
        }else if ($grp==2){
            $getGames = "SELECT * FROM tbl_games WHERE tbl_games.games_id > 5 AND tbl_games.games_id < 11";
        }else if ($grp==3){
            $getGames = "SELECT * FROM tbl_games WHERE tbl_games.games_id > 10 AND tbl_games.games_id < 16";
        }
        else if ($grp==4){
            $getGames = "SELECT * FROM tbl_games WHERE tbl_games.games_id > 15 AND tbl_games.games_id < 21";
        }else if ($grp==5){
            $getGames = "SELECT * FROM tbl_games WHERE tbl_games.games_id > 20 AND tbl_games.games_id < 26";
        }

     }else if(empty($_GET['userSearch'])){
        echo "4";
        $getGames = "SELECT * FROM tbl_games WHERE games_id <6";//Will Display 5 items
        //$getGames = "SELECT * FROM tbl_games";//Will Display all items
    }

    $getQuery = mysql_query($getGames);
    //Step 2
    $numRows = mysql_num_rows($getQuery);
<?php
                    if($numRows==0){
                        echo "No go. ".$srch." was not found";
                    }else{
                        while($result =  mysql_fetch_array($getQuery)) {
                            echo "<div class=\"span2\">";
                            echo "<img src=\"images/".$result["games_img"]."\" >";
                            echo "<h3>".$result["games_name"]."</h3>";
                            echo "<p>".$result["games_price"]."</p>";
                            echo "<p>".$result["games_avail"]."</p>";
                            echo "<div>";
                            echo "<a href=\"gamedetails.php?id=".$result["games_id"]."\">
        More Details...</a><br><br>";
                            echo "</div>";
                            echo "</div>";
                        } 
                    }
                ?>
if(isset($\u GET['span'])){
呼应“3”;
$grp=$_GET['span'];
如果($grp==1){
$getGames=“从tbl_games.games_id<6的tbl_games中选择*”;
}否则如果($grp==2){
$getGames=“从tbl_games.games_id>5和tbl_games.games_id<11的tbl_游戏中选择*”;
}否则如果($grp==3){
$getGames=“从tbl_games.games_id>10和tbl_games.games_id<16的tbl_游戏中选择*”;
}
否则,如果($grp==4){
$getGames=“从tbl_games.games_id>15和tbl_games.games_id<21的tbl_游戏中选择*”;
}否则,如果($grp==5){
$getGames=“从tbl_games.games_id>20和tbl_games.games_id<26的tbl_游戏中选择*”;
}
}else if(空($\u GET['userSearch'])){
呼应“4”;

$getGames=“SELECT*FROM tbl_games,其中games_id模数运算符非常适合这种情况。请执行以下操作:

echo '<div>';
for ($i = 0; $i < 25; $i++) {
    if ($i % 5 === 0 && $i !== 0) {
        echo '</div><div>';
    }

    // Do output here
}
echo '</div>';
echo';
对于($i=0;$i<25;$i++){
如果($i%5==0&&$i!==0){
回声';
}
//在这里做输出吗
}
回声';

这样做的目的是每5次打印一次新的div。在您的情况下,请记录您所做的记录的数量,并将其用作比较。

模数运算符非常适合这种情况。请执行以下操作:

echo '<div>';
for ($i = 0; $i < 25; $i++) {
    if ($i % 5 === 0 && $i !== 0) {
        echo '</div><div>';
    }

    // Do output here
}
echo '</div>';
echo';
对于($i=0;$i<25;$i++){
如果($i%5==0&&$i!==0){
回声';
}
//在这里做输出吗
}
回声';

这样做的目的是每5次打印一次新的div。在您的情况下,记录您所做的记录的数量,并将其用作比较。

在while循环之前添加一个计数器,并使用模函数检查您是否处于第5个循环

$counter = 0;
while (){
    $counter++;

    // do normal loop stuff here

    if($counter%5 == 0) {
        // add your closing and opening div here

        if($counter == 25) {
            // you might not want to open a new div on the 25th loop
        }

    }

}

在while循环之前添加一个计数器,并使用模函数检查是否在第5个循环上

$counter = 0;
while (){
    $counter++;

    // do normal loop stuff here

    if($counter%5 == 0) {
        // add your closing and opening div here

        if($counter == 25) {
            // you might not want to open a new div on the 25th loop
        }

    }

}

可能重复的可能重复我编辑代码以正确输出您想要的div。我编辑代码以正确输出您想要的div。