Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help making a theatre website that uses PHP, JavaScript, HTML5, CSS, and

ID: 3769275 • Letter: I

Question

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 -
Currently I am trying to get my page to create an html table out of some sql data.

I think I understand what to do but am struggling with the construction of the php + sql parts.

In my booking.php file (general booking page) I have:

       $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['production']."</td>";
       echo "<td>".$row['date']."</td>";
       echo "<td>".$row['time']."</td></tr>";
    }
       echo "</table>";
         echo "</table>";

     ?>


This prints out a basic table. As an aside, how do I customise this table (add borders etc?)

My main question is how do I go about allowing a user to select a performance? I can add buttons next to each one but I then need to present information on available seats and prices from the database.
So I guess how do I create an onclick function or similar that can take a selection, then present the related database info?

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.

Other ways:

if you want to use php from external file. Just write all the php code in external file like table.php and save it in path

and include the file name in html using include.

for example:

<html>

<head></head>

<body>

<?php include 'table.php;?>

</body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote