<?php
$link = mysql_connect ( "localhost", "root", "vertrigo" );if (mysql_select_db ( "unite2", $link )) {
//echo "数据库连接成功";
}//查询
$sql = "select * from unite_voucher";
$result = mysql_query ( $sql, $link );$row = mysql_fetch_array ( $result );print_r ($row);
?>
<table width="500" border="1">
<tr>
<th scope="col">1</th>
<th scope="col">2</th>
<th scope="col">3</th>
<th scope="col">4</th>
</tr>
  <?php
while ( $row ) {
?>
     <tr>
<td><?php echo $row [0]?></td>
<td><?php echo $row [1]?></td>
<td><?php echo $row [2]?></td>
<td><?php echo $row [3]?></td>

</tr>
  
   <?php
//echo $row[0]." ".$row[1]."<br>";
$row = mysql_fetch_array ( $result );
}
mysql_close ( $link );
?>
</table>

解决方案 »

  1.   

    <?php
    $link = mysql_connect ( "localhost", "root", "vertrigo" );
    if (mysql_select_db ( "unite2", $link )) {
    //echo "数据库连接成功";
    }
    //查询
    $sql = "select * from unite_voucher";
    $result = mysql_query ( $sql, $link );
    ?>
    <table width="500" border="1">
    <tr>
    <th scope="col">1</th>
    <th scope="col">2</th>
    <th scope="col">3</th>
    <th scope="col">4</th>
    </tr>
    <?php
    while ( $row = mysql_fetch_array ( $result ) ) {
    ?>
    <tr>
    <td><?php echo $row [0]?></td>
    <td><?php echo $row [1]?></td>
    <td><?php echo $row [2]?></td>
    <td><?php echo $row [3]?></td>
    </tr>
    <?php
    }
    mysql_close ( $link );
    ?>
    </table>
    还有,你这个SQL语句确定在数据库中有返回结果吗?
      

  2.   

    先在mysql里测试下 select * from unite_voucher 能不能查询,如果正常就按1楼的代码就可!
      

  3.   

    mysql_fetch_array 换成 mysql_fetch_row 看看 
    用 $row[fieldname]另外还有权限与编码问题
    SET character_set_connection= utf8; //gb2312
      

  4.   

    先看表中有没有数据! mysql_fetch_array是从结果集取出一行数组作为关联数组,或数字数组,两者兼得
      

  5.   

    同意。
    一把sql语句要先在sql中写好,然后执行下,看有没有错误,能不能查出数据。
    这样效率高点,要不然在程序中写出错了很难找
      

  6.   

    mysql_fetch_array 换成 mysql_fetch_row 看看 
    或者显示的时候直接改为:
    $row['字段名']而不是你以前的$row[2]数字形式!