php(限制while循环显示的记录数)急急!!!!!!!!!!

liangling221 2008-04-16 01:10:13
$str="select tgbs as bs,tgbt as bt from tgsp where status = 1 and getdate() between isnull(fbqsrq,getdate()) and isnull(fbjzrq,getdate()) order by case when gmcs is null then 999999 else gmcs end desc";
$ph_query = tep_db_query($str);

<?
while($paih = tep_db_fetch_array($ph_query)){
?>
<li>· <? echo ' <a class="L100" title="'.$paih['bt'].'" href="'.tep_href_link('tuangoushow.php','id='.$paih['bs']) .'" target=_parent> <script>document.write("'.$paih['bt'].'".length>9?"'.$paih['bt'].'".substring(0,9)+"...":"'.$paih['bt'].'"); </script> </a> ' ?> </li>
<?php
}
?>
比如sql语句能查出10条记录,但是在用while 循环的时候只显示7条,在不改变sql 语句的情况下只改变while循环
来实现这个效果,请大家帮忙..谢谢.....
...全文
239 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zcl8624 2008-04-16
  • 打赏
  • 举报
回复

$str="select tgbs as bs,tgbt as bt from tgsp where status = 1 and getdate() between isnull(fbqsrq,getdate()) and isnull(fbjzrq,getdate()) order by case when gmcs is null then 999999 else gmcs end desc";
$ph_query = tep_db_query($str);

<?
$i = 0;//增加一个自增字段
$num = 7;//需要的记录数
while($paih = tep_db_fetch_array($ph_query)){
if($i == $num){ //如果记录数与已循环次数相等,则跳出循环
break;
}
?>
<li>· <? echo ' <a class="L100" title="'.$paih['bt'].'" href="'.tep_href_link('tuangoushow.php','id='.$paih['bs']) .'" target=_parent> <script>document.write("'.$paih['bt'].'".length>9?"'.$paih['bt'].'".substring(0,9)+"...":"'.$paih['bt'].'"); </script> </a> ' ?> </li>
<?php
$i++;
}
?>





leec1981 2008-04-16
  • 打赏
  • 举报
回复
设置一个变量,显示一条加1,显示7条后就不再显示了

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧