if ($rs_row=mssql_fetch_array($rs)){
$i=0;
$strResult= " <tr height=30> <th>序号 </th> <th>编码 </th> <th>名称 </th> </tr>"; 
do {

$strResult= $strResult."<tr height=25 ><td align=center>".$rs_row[0]."</td><td class=border1  align=left>".$rs_row[1]."</td><td align=left>".$rs_row[2]."</td></tr>";  $i++;
}while($rs_row=mssql_fetch_array($rs));
}读出来却是从第二条记录开始显示的,i已经是0了,为什么读不到第一条记录呢?

解决方案 »

  1.   

    这样做:
    if ($rs_row=mssql_fetch_array($rs)){ 
    $i=0; 
    $strResult= " <tr height=30> <th>序号 </th> <th>编码 </th> <th>名称 </th> </tr>"; 
    while($rs_row=mssql_fetch_array($rs)) { $strResult= $strResult." <tr height=25 > <td align=center>".$rs_row[0]." </td> <td class=border1  align=left>".$rs_row[1]." </td> <td align=left>".$rs_row[2]." </td> </tr>"; $i++; 
    }; 
      

  2.   

    if ($rs_row=mssql_fetch_array($rs)){ 
    $rs_row=mssql_fetch_array($rs)读取了两次。(不理睬do while的执行顺序)$i=0;
    $strResult=" <tr height=30> <th>序号 </th> <th>编码 </th> <th>名称 </th> </tr>"; 
    while($rs_row=mssql_fetch_array($rs))

    $strResult= $strResult." <tr height=25 > <td align=center>".$rs_row[0]." </td> <td class=border1  align=left>".$rs_row[1]." </td> <td align=left>".$rs_row[2]." </td> </tr>"; 
    $i++; 
    }
      

  3.   

    LS说出了问题所在,因为 马上说起来mssql_fetch_...这样的函数操作对数据集是消耗性的。不过LS的解决方案在没有记录的时候还是会出现一个表头。这个可能和LZ本身的想法有些不同。至于如何修改,让LZ自己定了。