Hello, I need help making a theatre website that uses PHP, JavaScript, HTML5, CS
ID: 3769204 • Letter: H
Question
Hello,
I need help making a theatre website that uses PHP, JavaScript, HTML5, CSS, and MySQL.
I have my basic structure and a little jsp. My issue is with the sql and php -
What I need to do is:
Present a list of productions and performance times from the database, then allow the user to select a performance. I have made my performance page without referencing the database but intend on having this link to my booking page, which will display the database info.
Present information on available seats and prices from the current state of the database
Allow the user to book one or more seats
Confirm booking details and show total cost
Allow the user to enter the customer name and email address, and confirm the purchase.
I understand what to do but am struggling with the construction of the php + sql parts.
so for example:
<?php // retrieve productions
$conn = connect();
$sql = "select * from performance order by perfDate;";
$handle = $conn->prepare($sql);
$handle->execute();
$conn = null;
$res = $handle->fetchAll();
echo "<table><tr><th>Production</th><th>Dates</th><th>Times</th>";
foreach($res as $row) {
echo "<li>".$row['row_no']." - ".$row['area_name']."</li>";
}
echo "</table>";
?>
The above should retrieve the results of a database. How do I go about printing these results to an html table?
Should the table be in a different file? If so how do I go about referencing the php file?
Can someone please help me understand this asap?
Explanation / Answer
You can print the results retrieved from the sql data in the same file where you have written html.
You can just use data retrieved from the sql by using php in between html.
for example:
<html>
<head><title>example</title></head>
<body>
<!-- some html code -->
<h2>Table results</h2>
<?php // retrieve productions
$conn = connect();
$sql = "select * from performance order by perfDate;";
$handle = $conn->prepare($sql);
$handle->execute();
$conn = null;
$res = $handle->fetchAll();
echo "<table><tr><th>Production</th><th>Dates</th><th>Times</th></tr>";
foreach($res as $row) {
echo "<tr><td>".$row['row_no']." </td> <td>".$row['area_name']."</td></tr>";
}
echo "</table>";
?>
</body>
</html>
So just use php code by starting php tags in between body.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.