简体   繁体   中英

php mysql table creation on web browser need to add in headings

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

This code is from my uni and it reads in tables from mysql and displays them in a table

im a php noob ive been trying to add headnings to the table called name, releasedate

how can i do this in code??

can anyone help??

Here you go:

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>

Try as below :

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

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