2015-09-07 22 views
1
//replace the following with your details. Dbname is your username by default. 
$con = mysqli_connect("info20003db.eng.unimelb.edu.au","geehwank","2058","geehwank"); 

// Check connection 
if (mysqli_connect_errno()) { 
    echo "Could not connect to MySQL for the following reason: " . mysqli_connect_error(); 
} 

/* this lists the name and release date of all action movies */ 
echo "<table border='1'>"; 
$result = mysqli_query($con,"SELECT name, release_date FROM Movie WHERE genre = 'action'"); 

while($row = mysqli_fetch_array($result)) { 
    echo "<tr>"; 
    echo "<td>" . $row['name'] . "</td><td>" . $row['release_date'] . "</td>"; 
    echo "</tr>"; 
} 
mysqli_close($con); 

此代碼是從我的UNI 並在表從MySQL 讀取並顯示在一個表中PHP MySQL表的創建需要在標題

IM一個PHP小白 我一直加試圖將名稱添加到名爲 的名單,釋放

我該如何在代碼中執行此操作?

任何人都可以幫忙?

+0

你說你一直在努力。你有什麼嘗試?結果是什麼?請告訴我們。 – Kuya

回答

0

嘗試如下:

<html> 
<head><title>Lab F</title></head> 
<body> 
<h1> Lab F - SELECT Example</h1> 
<p> 
This PHP code runs an SQL query, and displays the answers in an HTML table. 
</p> 
<p> 
<br> 



<?php 

//replace the following with your details. Dbname is your username by default. 
$con = mysqli_connect("info20003db.eng.unimelb.edu.au","geehwank","2058","geehwank"); 

// Check connection 
if (mysqli_connect_errno()) { 
    echo "Could not connect to MySQL for the following reason: " . mysqli_connect_error(); 
} 

/* this lists the name and release date of all action movies */ 
echo "<table border='1'>"; 
$result = mysqli_query($con,"SELECT name, release_date FROM Movie WHERE genre = 'action'"); 
echo "<tr><td>Name</td><td>Release Date</td></tr>"; 
while($row = mysqli_fetch_array($result)) { 
      echo "<tr>"; 
      echo "<td>" . $row['name'] . "</td><td>" . $row['release_date'] . "</td>"; 
      echo "</tr>";} 
mysqli_close($con); 
?> 

</table> 
</body> 
</html> 
2

在這裏你去:

echo "<table border='1'><thead><tr><th>Name</th><th>Release Date</th></tr></thead><tbody>"; 
$result = mysqli_query($con,"SELECT name, release_date FROM Movie WHERE genre = 'action'"); 

while($row = mysqli_fetch_array($result)) { 
      echo "<tr>"; 
      echo "<td>" . $row['name'] . "</td><td>" . $row['release_date'] . "</td>"; 
      echo "</tr>";} 
mysqli_close($con); 
?> 

</tbody></table>