我的数据库中有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>
答案 0 :(得分: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>
答案 1 :(得分:0)
<?php $i=0;
while($record= mysql_fetch_array($records))
{
//your code here
$i++;
if($i%10==0)
{
echo '<ul></ul>';
}
} ?>
答案 2 :(得分: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>