Ich möchte ein Kontrollkästchen für jede Abfrage auf diese Weise, wenn die Tabelle mit Daten aus der Datenbank gefüllt wird, gibt es auch ein Kontrollkästchen, um die Buchung für jede Abfrage zu bestätigen.PHP-Datei mit Checkboxen in einer Tabelle, die Daten aus einer Datenbank holt?
Ich möchte auch wissen, wie einen Skript zu erstellen, die einmal ein einziges Kontrollkästchen ausgewählt wurde, ich einreichen klicken und es nimmt mich auf einem andere Seite, die Werte anzeigt (route_no, to_city, from_city und Preis) basierend auf dem ausgewählten Kontrollkästchen und route_no entsprechend dem ausgewählten Kontrollkästchen. route_no ist auto_incrementing und ist ein Primärschlüssel (Werte von route_no reichen von 0-49).
das ist mein HTML-Formular
<html>
<head>
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","display.php?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<form>
<select name="to_city" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="Sydney">Sydney</option>
<option value="Brisbane">Brisbane</option>
<option value="Adelaide">Adelaide</option>
<option value="Newcastle">Newcastle</option>
</select>
</form>
<br>
</body>
</html>
und unten ist meine PHP-Datei, der Text hat, das zeigt, was ich acheive will. Der Text wurde auskommentiert.
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
<?php
$q = strval($_GET['q']);
$con = mysqli_connect('localhost','root','','mydb');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"flights");
$sql="SELECT * FROM flights WHERE to_city = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th>Route_no</th>
<th>to_city</th>
<th>from_city</th>
<th>price</th>
<th>Confirm</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['route_no'] . "</td>";
echo "<td>" . $row['to_city'] . "</td>";
echo "<td>" . $row['from_city'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
/// I want a checkbox here for each query that way when the table is populated with data from the db, there is also a checkbox to confirm that booking for each query result.
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</body>
</html>
-
"radio"
ändern es zeigt: Parse error: syntax error, unerwartet ‚Checkbox‘ (T_STRING), erwarten ‚‘ oder ‚;‘ in C: \ wamp64 \ www \ display.php on line 29 –Ich habe die Antwort bearbeitet. Bitte überprüfen Sie jetzt @ Novice_29 – Bhugy
Parse-Fehler: Syntaxfehler, unerwartete 'Echo' (T_ECHO), erwartet ',' oder ';' in C: \ wamp64 \ www \ display.php on line 30 –