-1

我的数据库中有 20 行,我在主页 index.php 中有一个标题,其中我有两个类,我想在一个类中显示 10 条记录,在另一个类中显示 10 条记录。所以请帮助我提前谢谢

<li>
    <a href="index.php" class="parent"><span>Home</span></a>
    <div class="columns two">
        <?php 
            $qry = "SELECT `SectionId`, `Title` FROM `section`";
            $records = mysql_query($qry);
            $num_of_rows = mysql_num_rows($records) / 2;
            while($record= mysql_fetch_array($records))
            {
                ?>
                    <ul class="one">
                        <li>
                            <a href="department.php?sId=<?php echo $record['SectionId'];?>">
                                <span><?php echo $record['Title']; ?> </span>
                            </a>
                        </li>
                    </ul>
                    <ul class="two">
                        <li>
                            <a href="department.php?sId=<?php echo $record['SectionId'];?>">
                                <span><?php echo $record['Title']; ?></span>
                            </a>
                        </li>
                    </ul>
                <?php 
            } 
        ?>
    </div>
</li>
4

3 回答 3

1
<li><a href="index.php" class="parent"><span>Home</span></a>
        <div class="columns two">
           <?php
                    $qry = "SELECT `SectionId`, `Title` FROM `section`";

                    $records = mysql_query($qry);

                    $num_of_rows = mysql_num_rows($records);

                    $m = 0;

                    while($record= mysql_fetch_array($records))
                    {
               if($m<10){
            ?>

            <ul class="one">

               <li>
                    <a href="department.php?sId=<?php echo $record['SectionId'];?>">
                        <span>
                            <?php
                                    echo $record['Title'];

                            ?>
                        </span>
                    </a>
               </li>
             </ul>
            <?php } else { ?>
            <ul class="two">

               <li>
                    <a href="department.php?sId=<?php echo $record['SectionId'];?>">
                        <span>
                            <?php
                                    echo $record['Title'];

                            ?>
                        </span>
                    </a>
               </li>
             </ul>
                <?php  } $m++;

                        }
                ?>
          </div>
      </li>
于 2013-08-27T07:53:39.860 回答
0
<?php $i=0;
while($record= mysql_fetch_array($records))
{
//your code here
$i++;
if($i%10==0)
{
 echo '<ul></ul>';
}
} ?>
于 2013-08-27T08:02:33.793 回答
0

怎么样:

<?php
$qry = "SELECT `SectionId`, `Title` FROM `section`";
$records = mysql_query($qry);
$num_of_rows = mysql_num_rows($records) / 2;
?>
        <ul class="one">
<?php
$nbrec=0;
while($record= mysql_fetch_array($records)) {
    if (++$nbrec == 10) {
    ?>
        </ul>
        <ul class="two">
    <?php
    }
    ?>
            <li>
                <a href="department.php?sId=<?php echo $record['SectionId'];?>">
                    <span><?php echo $record['Title']; ?> </span>
                </a>
            </li>
    <?php 
}
?>
        </ul>
于 2013-08-27T08:49:35.037 回答