I'd like to be able to change the SQL query to another with the press of a button, I need about 8 buttons and 8 separate queries. If possible, I'd like to be able to do this without refreshing the page, just updating the table.
This is my current code:
<?php
include 'table/modes.php';
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT m.MapName, SEC_TO_TIME(TRUNCATE(t.Time,3)) AS Time, p.User FROM times t INNER JOIN maps m ON t.MapID = m.MapID INNER JOIN players p ON p.PlayerID = t.PlayerID INNER JOIN (SELECT t.MapId, MIN(t.time) as time FROM times t WHERE t.style = 0 and t.type = 0 GROUP BY t.MapId ) tmin ON tmin.MapId = t.MapId and tmin.time = t.time";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table class='table table-striped table-fixedheader sortable'><thead><tr><th data-defaultsort='asc'>Map</th><th>Time</th><th>Player</th></tr></thead><tbody style='height:300px' class='searchable'>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["MapName"]."</td><td>".$row["Time"]."</td><td>".$row["User"]."</td></tr>";
}
echo "</tbody></table>";
} else {
echo "0 results";
}
$conn->close();
?>
Currently that fetches data for a table and displays it. I'd like buttons that execute different queries this and update the table without refreshing the page (not sure if possible).
How can this be achieved?
The main values I am looking to change in each query is this WHERE t.style = 0 and t.type = 0 too different numbers.