如何从PHP中的表打印数据?

时间:2014-02-10 08:43:31

标签: php

如何在浏览器上打印d_name?如何在此脚本中使用for循环或任何其他条件在<ul><li>标记中显示5 d_name?

我想要这样的输出

  

USER5

     

user4

     

user3

     

user2

     

用户1

我的配置文件是:     

if (mysqli_connect_errno())
 {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }
 ?> 



 session_start();

 if(!isset($_SESSION['****']) and (!$_SESSION['auth'])==*)
 {
    header('Location:index.php');
  }

  include 'config.php';
  $list="select d_name from donated order by d_id desc limit 5;";

  $data=mysqli_query($con,$list);

  if ($uresult= mysqli_query($con,$list))
     {
       //counting rows
       $urows= mysqli_num_rows($uresult);
     }  
 echo $urows;

$info = mysqli_fetch_array($data);

2 个答案:

答案 0 :(得分:0)

尝试

while($info = mysqli_fetch_array($data))
{
   print_r($info);
}

OR

  while($info = mysqli_fetch_array($data))
    {
       echo $info['d_name'];
    }

答案 1 :(得分:0)

以下是一种方法:

$data = mysqli_query($con,$list)or die(mysql_error());

$resultTable = ‘<table>’;

while ($row = mysql_fetch_array($data))
    {
        $resultTable .= '<tr><td>' . $row['d_name'] . '</td></tr>';
    }

$resultTable .= ‘</table>’;

echo $resultTable;