// Ein Hauptproblem ist, sobald ein Benutzer einen Radiobutton auswählt und Treffer den Wert abschickt, sendet er ein Array. Ich möchte diese individuellen Abfragen (route_no, to_city, from_city, price) auf der Seite nextpage.php in einer Tabelle neben ihren Tabellenköpfen oder neben den Tags platzieren. Ich kann dies nicht tun, weil der Wert "confirm" alle Abfragen als eine einzige Zeichenfolge/ein einzelnes Array sendet. Wie kann ich das beheben, bitte hilf mir. enter image description hereWie kann ich mehrere Werte von einem Optionsfeld abrufen und sie dann einzelnen Variablen zuweisen und sie auf einer Seite anzeigen?
hier ist meine HTML-Seite
<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","display3.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="3">Joseph Swanson</option>
<option value="4">Glenn Quagmire</option>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here...</b></div>
</body>
</html>
hier ist meine display3.php Seite
<!DOCTYPE html>
<style>
td{
padding-top: 10px;
padding-right: 10px;
padding-bottom: 10px;
padding-left: 10px;
}
</style>
<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);
?>
<form action="nextpage.php" method="get">
<?php
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)) {
$all_values = $row['route_no'] .",".$row['to_city'].",".$row['from_city'].",".$row['price'];
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>";
echo "<td><input type='radio' name='Confirm' value='".$all_values."'></td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
<input type="submit" value="Submit">
</form>
</body>
</html>
hier meine nextpage.php Funktion
<!DOCTYPE html>
<head>
<style>
td{
padding-top: 10px;
padding-right: 10px;
padding-bottom: 10px;
padding-left: 10px;
}
</style>
<body>
<h1>Booking Details</h1>
<h2>Flight No.</h2>
<h2>to_city</h2>
<h2>from_city</h2>
<h2>Price</h2>
<?php
echo $_GET['Confirm'];
?>
<table >
</body>
</head>
</html>
Ich kann das verwenden, weil ich Werte aus einer Datenbank übernehmen. Bitte schauen Sie sich meine Dateien genau an. Wenn ich $ str = "4, Sydney, Canberra, 120,00" verwenden würde; das wäre hardcoding, das kann ich nicht machen weil was wenn ich eine andere abfrage/radiobutton auswähle ?? –
übergeben Sie Ihre Variable direkt in explode (",", $ from_table_value_dynamic) – JYoThI
ich zwinge dich nicht hartcode ist nur ein Beispiel Mann – JYoThI