我想在用户选择从动态下拉列表框中选择一个选项后显示相应的MySQL表列寻求帮助。 我真的不知道我在哪里出了错:(请帮助:(
我有3个MySQL表:建筑物,delivery_transaction和位置,都相互连接。 主表是交货的交易:
[delivery_transaction表,其中building_ID和LOCATION_ID是FKS从剩余的2代表] [1]
其中,如果用户点击任何建筑物名称出现在下拉列表中,将只显示我从主表中查询如下列。
这里是我到目前为止的代码:
<form name="bldg_form" method="post" action="">
<?php
//establish sql connection with db
$con = new mysqli("localhost" ,"root" ,"" ,"user_databases");
if(!$con)
{
echo "Failed to connect!";
}
//select columns from delivery_transaction, buildings and location table
$query = mysqli_query($con, "SELECT delivery_status, starting_time,
arrival_time, duration, buildings.building_name,
location.location_name from delivery_transaction, buildings,
location where delivery_transaction.building_ID =
buildings.building_ID and delivery_transaction.location_ID =
location.location_ID");
?>
<!--Creates dropdown box-->
<select name = 'bldg'>
<option value = "">Choose Building</option>;
<?php
while($row = mysqli_fetch_assoc($query))
{
if($row['building_name'] == $selectedbldg)
{
echo '<option value = \"'.$row['building_ID'].'"
selected>'.$row['building_name'].'</option>';
}
else
{
echo '<option value
=\"'.$row['building_ID'].'">'.$row['building_name'].'</option>';
}
}
?>
</select>
<input type="submit" name="view"/>
</form>
<section class="row text-center placeholders">
<div class="table-responsive">
<p>
<table class="table table-striped">
<thead>
<tr>
<th>Delivery Status</th>
<th>Starting Time</th>
<th>Arrival Time</th>
<th>Duration</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<tr>
<?php
if(isset($_POST['bldg']))
{
while($row = mysqli_fetch_row($query))
{
echo "<tr>"."<td>".$row['delivery_status']."</td>"."
<td>".$row['starting_time']."</td>"."
<td>".$row['arrival_time']."</td>"."
<td>".$row['duration']."</td>"."
<td>".$row['location_name']."</td>"."</tr>";
}
}
else
{
echo "No results to display";
}
?>
</tr>
</tbody>
</table>
</p>
</div>
</section>
</main>
What I want to do is if user clicks on an option, it will display the
corresponding table just like I queried. However, nothing displays :(
[This link shows user choosing an option][2]
[1]: https://i.stack.imgur.com/H78Gp.png
[2]: https://i.stack.imgur.com/pA6gI.png