使用mysqli_fetch_array在PHP表MySQL中显示数据

时间:2015-11-27 14:14:36

标签: php mysql

目前,数据显示在一行中,我需要以表格格式显示。

将有5个标题符合5'数据类型'下方。

echo "<h3>search results for <i>". $keyword."</i></h3><br>";
while($result_arr = mysqli_fetch_array( $result )) 
{ 
echo $result_arr['datatype1']; 
echo $result_arr['2'];
echo $result_arr['3'];
echo $result_arr['4'];
echo $result_arr['5'];
}
$anymatches=mysqli_num_rows($result); 

1 个答案:

答案 0 :(得分:0)

只是将输出格式化为@ Phil-Cooper说:

echo "<h3>search results for <i>".$keyword."</i></h3><br><table><tr><th>Heading 1</th><th>Heading 2</th><th>Heading 3</th><th>Heading 4</th><th>Heading 5</th></tr>";
while($result_arr = mysqli_fetch_array( $result )) 
{ 
echo "<tr><th>".$result_arr['datatype1']."</th>"; 
echo "<th>".$result_arr['2']."</th>";
echo "<th>".$result_arr['3']."</th>";
echo "<th>".$result_arr['4']."</th>";
echo "<th>".$result_arr['5']."</th></tr>";
}
echo "</table>";
$anymatches=mysqli_num_rows($result);