How to display joined entries from two tables in a database as an HTML table?
<p>Hope you all are well.</p>

<p>I have 3 database tables:</p>

<p><a href="https://i.stack.imgur.com/2nosy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2nosy.png" alt="&#39;Events&#39; table with event ID, name and location"></a> 'Events' table with event ID, name and location.</p>

<p><a href="https://i.stack.imgur.com/FgWC0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FgWC0.png" alt="&#39;Students&#39; Table with StudentID, First Name, Last name, House and Year/grade"></a> 'Students' Table with StudentID, First Name, Last name, House and Year/grade.</p>

<p>and <a href="https://i.stack.imgur.com/TrDix.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TrDix.png" alt="an &#39;entries&#39; table with StudentID, and two events that they choose to enroll in."></a> an 'entries' table with StudentID, and two events that they choose to enroll in.</p>

<p>How can I create an SQL code that allows me to display an event? For example, if I wanted to display...</p>

<p><a href="https://i.stack.imgur.com/vS0fv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vS0fv.png" alt="The year 7 girl&#39;s 100m run."></a> The year 7 girl's 100m run.</p>

<p>In the form of a table similar to this one:</p>

<p><a href="https://i.stack.imgur.com/RsLGN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RsLGN.png" alt="sample table with an empty space for people to manually write times in."></a> sample table with an empty space for people to manually write times in.</p>

<p>How would I do that, so that it accepts input from the combo boxes and finds the students with this event chosen(either in the Ev1 or Ev2 field) and lists them out, when the information is spread out over 3 different tables?</p>

<p>Here's the code I have, but I don't think it works.</p>

<pre><code>&lt;!doctype html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset="UTF-8"&gt;
&lt;title&gt;Sports Day Lineup Generator&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

Hello! What page would you like to see?&lt;br&gt;&lt;br&gt;

&lt;form id="form2" name="form2" method="POST" action="display.php"&gt;
&lt;select id="Year"&gt;&lt;option value="7"&gt;Y7&lt;/option&gt;&lt;option value="8"&gt;Y8&lt;/option&gt;&lt;option value="9"&gt;Y9&lt;/option&gt;&lt;option value="10"&gt;Y10&lt;/option&gt;&lt;option value="11"&gt;Y11&lt;/option&gt;&lt;option value="12"&gt;IB1&lt;/option&gt;&lt;option value="13"&gt;IB2&lt;/option&gt;&lt;/select&gt;

&lt;select id="Gender"&gt;&lt;option value="0"&gt;Girls&lt;/option&gt;&lt;option value="1"&gt;Boys&lt;/option&gt;&lt;/select&gt;

&lt;select id="Event"&gt;
&lt;option value="1"&gt;100m&lt;/option&gt;&lt;option value="2 relay"&gt;100m Relay&lt;/option&gt;&lt;option value="3"&gt;400m&lt;/option&gt;&lt;option value="4"&gt;800m&lt;/option&gt;&lt;option value="5"&gt;Indoor Sports&lt;/option&gt;&lt;option value="6"&gt;High Jump&lt;/option&gt;&lt;option value="7"&gt;Long Jump&lt;/option&gt;&lt;option value="8"&gt;Triple Jump&lt;/option&gt;&lt;option value="9"&gt;Shotput&lt;/option&gt;
&lt;/select&gt;&lt;br&gt;
&lt;input type="submit" value="generate"&gt;
&lt;/form&gt;
OR &lt;form id="form2" name="form2" method="POST" action="displayAll.php"&gt;&lt;input type="submit" value="generate all tables"&gt;&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>this is the adminPage.php, and this:</p>

<pre><code>&lt;?php 

//This gets all the other information from the form 
$id=$_POST['studID']; 
$event1=$_POST['event1']; 
$event2=$_POST['event2']; 

// Connects to your Database 
// require_once 'login.php';
$db_hostname = 'localhost';
$db_username = 'root';
$db_password = 'ITGS!!!';
$db_server=mysql_connect($db_hostname,$db_username,$db_password);

if(!$db_server) die("Unable to connect to MySQL" .mysql_error());

$db_database='sportsDay';

mysql_select_db($db_database,$db_server)
or die("Unable to connect to database. " .mysql_error()); 

$sql = "SELECT Entries.stID, Students.fName, Students.lName, Students.gender, Events.eventID
</code></pre>

<p>FROM Events
INNER JOIN Customers
ON Students.stID=Entries.stID; ";
    $result = $db_server->query($sql);</p>

<pre><code>if ($result-&gt;num_rows &gt; 0) {
    echo "&lt;table&gt;&lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;House&lt;/th&gt;&lt;/tr&gt;";
    // output data of each row
    while($row = $result-&gt;fetch_assoc()) {
        echo "&lt;tr&gt;&lt;td&gt;".$row["fName"]." ".$row["lName"]."&lt;/td&gt;&lt;td&gt;".$row["house"]."&lt;/td&gt;&lt;/tr&gt;";
    }
    echo "&lt;/table&gt;";
} else {
    echo "0 results";
}
$conn-&gt;close();

     ?&gt; 

     &lt;html&gt;

     &lt;body&gt;
     &lt;/body&gt;
     &lt;/html&gt;
</code></pre>

<p>is my display.php.</p>