我从特定列车编号的车站的数据库值创建了一个下拉列表。当我从下拉列表中选择两个电台时,我想显示特定列车编号的两个选定电台之间的电台列表,但我无法这样做。我用它来在两个电台之间进行选择,但它没有给出结果。
<?php
include "config.php"; // Database connection using PDO
if(isset($_POST['submit'])){
$tnumber=$_POST['tnumber'];
$sql="select sname from traininfo where tnumber = '".$tnumber."' ORDER by day, arrival ASC ";
echo $sql;
}
/* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */
?>
<form action="#" method="post">
<?php
echo "<select name='to'>
<option value=''>Station Name</option>"; // list box select command
foreach ($dbo->query($sql) as $row){//Array or records stored in $row
echo "<option value=$row[sname]>$row[sname]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
echo "<select name='from'>
<option value=''>Station Name</option>"; // list box select command
foreach ($dbo->query($sql) as $row){//Array or records stored in $row
echo "<option value=$row[sname]>$row[sname]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
?>
<input type="submit" name="next" value="Get Selected Values" />
</form>
<?php
include "config.php";
if(isset($_POST['next'])){
$selected_val = $_POST['to'];
$selected_val2 = $_POST['from']; // Storing Selected Value In Variable
echo "You slept at :" .$selected_val;
// Displaying Selected Value
echo "You wake up at:" .$selected_val2; // Displaying Selected Value
$sql5 = "SELECT (sname, tname, tnumber, arrival, depart, day) FROM stations WHERE sname BETWEEN sname='$selected_val' and sname='$selected_val2' ORDER BY day, arrival ASC";
echo $sql5;
$q5=mysql_query($sql5);
}
else
{
$sql5="SELECT * FROM stations";
echo $sql5;
$q5=mysql_query($sql5);
}
?>
<html>
<body>
<table>
<?php
while($res=mysql_fetch_array($q5)){
?>
<tr>
<th>id</th><br>
<th>Station Name</th><br>
<th>Train name</th><br>
<th>Train Number</th><br>
<th>Arrival</th><br>
<th>Departure</th><br>
<th>Day</th>
</tr>
<tr>
<td><?php echo $res['id'];?></td>
<td><?php echo $res['sname'];?></td>
<td><?php echo $res['tname'];?></td>
<td><?php echo $res['tnumber'];?></td>
<td><?php echo $res['arrival'];?></td>
<td><?php echo $res['depart'];?></td>
<td><?php echo $res['day'];?></td>
</tr>
<?php }
?>
</table>
</body>
</html>