简体   繁体   中英

Display data in a PHP table MySQL using mysqli_fetch_array

At the moment, the data is shown in a line, where I need it in a tabular format.

There would be 5 headings which would align to the 5 'data types' below.

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); 

It's just a case of formatting the output as @Phil-Cooper says:

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); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM