如何使用mysql在php中将行更改为cloumn

早安,我找到了很多例子,但仍然无法显示我想要的输出,请帮助我并谢谢。现在这样输出:

http://img.mukewang.com/6129a5000001e54302000081.jpg

 我想要这样的输出:

http://img.mukewang.com/6129a50b0001572a03940039.jpg


<?php

$servername = "localhost";$username = 'root';$password = "";$database = "ocall";

$mysqli = new mysqli("localhost", $username, $password, $database);$query = "SELECT * FROM timetable";


echo '<table border="1" ><tr><td><b> <font face="Arial">Day</font></td><td><b><font face="Arial">Date</font></td></tr>';


if ($result = $mysqli->query($query)) {while ($row = $result->fetch_assoc()) {$field1name = $row["Day"];$field2name = $row["Date"];


echo '

<tr><td>'.$field1name.'</td><td>'.$field2name.'</td></tr>';}$result->free();}

?>


侃侃无极
浏览 154回答 1
1回答

呼唤远方

一种方法是将值存储在单独的数组中。请尝试以下代码。<?php$servername = "localhost";$username = 'root';$password = "";$database = "ocall";$conn = new mysqli("localhost", $username, $password, $database);if(!$conn){echo "Error";}$query = "SELECT * FROM `timetable`";$result = mysqli_query($conn, $query);while($row = mysqli_fetch_assoc($result)){&nbsp; &nbsp; $daytime[] =&nbsp; $row['Day'] ;&nbsp; &nbsp; $dates[] = $row['Date'];}echo '<table border=1><tr><td>Day</td>';foreach($daytime as $d){echo '<td>'.$d.'</td>';}echo '</tr><tr><td>Dates</td>';foreach($dates as $d){echo '<td>'.$d.'</td>';}echo '</tr></table>'?>希望这对你有用。
打开App,查看更多内容
随时随地看视频慕课网APP