new to php and MYSQL,and would like some help, so please be gentle
I have some code which populates a HTML table using php echo.
The statement is:
$query= "SELECT Distinct AgeGrp, Gender,Dist, Stroke, First,
Family, Name, Year, Time, Event, Date
FROM JLSSWIMMING1
WHERE Year = '7'
and Stroke = 'Freestyle'" ;
I would like to add more select statements, then display the results in the same html table e.g.
$query2= "SELECT Distinct AgeGrp, Gender,Dist, Stroke, First,
Family, Name, Year, Time, Event, Date
FROM JLSSWIMMING1
WHERE Year = '7'
and Stroke = 'Backstroke'" ;
Thanks in advance
From research it look like I may need an array, (not a join), but I am struggling at this point.
Here is my current code:
<?php
try {
$pdo = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query= "SELECT Distinct AgeGrp, Gender,Dist, Stroke, First,
Family, Name, Year, Time, Event, Date
FROM JLSSWIMMING1
WHERE Year = '7'
and Stroke = 'Freestyle'" ;
$stmt = $pdo->prepare($query);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($result) > 0) {
echo "<br>";
echo '<table class="special-table">';
echo '<thead class="fixed-header">';
echo '<tr>
<th>Pos.</th>
<th class="left-align">Name</th>
<th class="left-align">Stroke</th>
<th>Yr</th>
<th>Dist</th>
<th>Time</th>
<th>AgeGrp</th>
<th>Gen.</th>
<th>DAte</th>
<th>Event</th>
</tr></thead><tbody>';
foreach ($result as $row) {
echo "<tr>
<td >" . $cnt++ ."</td>
<td class='left-align'>" . $row["Name"] . "</td>
<td class='left-align'>" . $row["Stroke"] . "</td>
<td >" . $row["Year"] . "</td>
<td >" . $row["Dist"] . "</td>
<td >" . $row["Time"] . "</td>
<td >" . $row["AgeGrp"] . "</td>
<td >" . $row["Gender"] . "</td>
<td >" . Date('d-m-y', strtotime($row['Date'])) . "</td>
<td >" . $row["Event"] . "</td>
</tr>";
}
echo "</table></div>";
} else {
echo "<br>";
echo "<br>";
echo "<div style='font-size: 42px;'> No results found ";
}
} catch (PDOException $e) {
die("Connection failed: " . $e->getMessage());
}
// Close the database connection
$pdo = null;
?>