一行显示多列的问题

hamier_hu 2006-12-30 09:20:41
我现在控制的是一行显示4条记录,但问题是如果正好是4条记录则能正常显示,但超出4条或小于4条的其他记录是显示不出来的,请各位大虾看看语句哪里错了?

代码如下:

$i=0;

$im=$na=$pl="";

while(list($theads1,$theads,$kid1,$key)=each($photothread)){

if($theads[path_s]==""){

$theads[path_s]=$theads[path];

}

$photo=$config[upload].$theads[path_s];

if($i==0){

$im.="<tr>";

$na.="<tr>";

$pl.="<tr>";

}

$im.="<td class=\"tupianpic\"><a href=\"/starlive/".$theads[singer_id]."/showphoto/".$theads[id]."\" target=\"_blank\"><img style=\"max-width: 110px; width:expression(this.width > 110 ? '110' : this.width);\" src=\"".$photo."\" /></a></td>";

$na.="<td>位置:<a href=\"/starlive/".$theads[singer_id]."\" target=\"_blank\">".$theads[cn_name]."</a></td>";

$sql="select count(pid) from bbs_posts where tid in (select tid from bbs_threads where topic_id=$theads[id]) and first<>1";

$result=$db->query($sql);

list($pinlun)=$db->fetchRow($result);

$pl.="<td>评论数:".$pinlun."</td>";

$i++;

if($i>3){

$im.="</tr>";

$na.="</tr>";

$pl.="</tr>";

echo "$im$na$pl";

$i=0;

$im=$na=$pl="";

}
...全文
189 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
iasky 2006-12-30
  • 打赏
  • 举报
回复
$i++;

if($i>3){
lvlfforever 2006-12-30
  • 打赏
  • 举报
回复
你的整段代码里 $i 最后只是 $i++ //等于 1 。
所以if($i>3) ...执行不到
zhys9 2006-12-30
  • 打赏
  • 举报
回复
表格怎么套的这么复杂...
lazyboy_wu 2006-12-30
  • 打赏
  • 举报
回复
是在while循环的外部!!
lazyboy_wu 2006-12-30
  • 打赏
  • 举报
回复
//最后加上一个
if($i>0){
$im.="</tr>";

$na.="</tr>";

$pl.="</tr>";

echo "$im$na$pl";
}
?>

为了美观也可以在上面的内容之前加上str_repeat("<td> </td>", 3 - $i)

//最后加上一个
if($i!=0){
$im.= str_repeat("<td> </td>", 3 - $i)."</tr>";

$na.= str_repeat("<td> </td>", 3 - $i)."</tr>";

$pl.= str_repeat("<td> </td>", 3 - $i)."</tr>";

echo "$im$na$pl";
}

21,886

社区成员

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

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