<?php
$exe="select count(*) as count from t_gongqiu  where info=0";
$result1=mysql_query($exe);
$rss=mysql_fetch_array($result1);
$ROW=$rss['count']/2;
$exec="select * from t_gongqiu  where info=0 order by Id desc limit 5";
$result=mysql_query($exec);//请求结果
$tb="<table>";
while($rs=mysql_fetch_array($result))

$id="$rs[Id]";
$rs['title']=substr($rs['title'],0,30);
if($rs["info"]==0)
{
$info1='[供应]';
}
else 
{
$info1='[求购]';
}
$tb.="<tr><td>$id</td><td>$rs['title']</td><td>$info1</td></tr>";
}
$tb.="</table>";
echo $tb;
?>
这样,循环一次就得到分三列的行了.
$rs['title']=substr($rs['title'],0,30);
$rs['title']=substr($rs['title'],0,30);
这个就不要两次那么多吧?

解决方案 »

  1.   

    <?php
    $exe="select count(*) as count from t_gongqiu  where info=0";
    $result1=mysql_query($exe);
    $rss=mysql_fetch_array($result1);
    $ROW=$rss['count']/2;
    $exec="select * from t_gongqiu  where info=0 order by Id desc limit 5";
    $result=mysql_query($exec);//请求结果
    $i=0;
    while($rs=mysql_fetch_array($result))

    $id="$rs[Id]";
    $rs['title']=substr($rs['title'],0,30);
    if($rs["info"]==0)
    {
    $info1='[供应]';
    }
    else 
    {
    $info1='[求购]';
    }
    echo "$rs['title']&nbsp;";
    $i++;
    if($i==3){
    $i=0;
    echo "<BR>-------------------------------------------<BR>";
    }?>
    是这样子吗?