各位大大,有个关于多选列表框的问题。代码://这是表1,可以显示所有时间段。
<form name="form_display_pickupInfo" method="post" action="include/admin_modify_timeslot.php">
<fieldset>
<legend>All timeslot:</legend>
<div align="left" style="width: 10px">
<?php
$query_timeslot_no="SELECT COUNT(pickup_time) FROM PICKUPTIME";
$rows_timeslot_no=queryMysql($query_timeslot_no);
$time_query="SELECT * FROM PICKUPTIME";
$result=queryMysql($time_query);
?> <select name="pickup_name_select[]" size="5" multiple>
<?php
for($i=0; $i<$rows_timeslot_no; $i++)
{
$rows_timeslot_name=mysql_fetch_array($result);
$timeslot_id = $rows_timeslot_name['pickup_time_id'];
$timeslot_name=$rows_timeslot_name['pickup_time'];

echo "<option value= $timeslot_id>$timeslot_name</option>";
}
?>
</select>
<br />
<input   type= "submit"   name= "S_delete_tslot"   value= "Delete"><br />
<input   type= "submit"   name= "S_add_tslot"   value= "Add to">
</div>
<div align="right" style="width:15px"></div>
</fieldset>
</form>//这是表2,能显示所有地点。
<form name="form_manage" method="post" enctype='multipart/form-data' action="admin_mgmt.php"> <fieldset>
<legend>Display destinations:</legend>
<div align="left">
<?php
$query_dest_no="SELECT COUNT(dest_name) FROM DESTINATION";
$rows_dest_no=queryMysql($query_dest_no);
$query_dest_name = "SELECT dest_id, dest_name, dest_description, img_url, google_map FROM DESTINATION";
$result=queryMysql($query_dest_name);
?> <select name="dest_name_select[]" size="7" multiple>
<?php
for($i=0; $i<$rows_dest_no; $i++)
{
$rows_dest_name=mysql_fetch_array($result);
$option_id = $rows_dest_name['dest_id'];
$option_name=$rows_dest_name['dest_name'];

echo "<option value= $option_id>$option_name</option>";
}
?>
</select>
<br />
<input   type= "submit"   name= "submit"   value= "Display"> <br />
<input   type= "submit"   name= "submit"   value= "Delete">
</div>
</fieldset>
</form>//这是表3,当选择表2中地点(destination)的时候,自动显示出对应可用的时间段
<form name="form_display_pickupInfo" method="post" action="admin_mgmt.php">
<div style="float:left">
<fieldset style="width:80px">
<legend>Current timeslot:</legend>

<?php
$destination_id=$_POST['dest_name_select'][0];
$query_c_timeslot_no="SELECT COUNT(pickup_time_id) FROM DEST_PICKUP WHERE dest_id='$destination_id'";
$rows_timeslot_no=queryMysql($query_timeslot_no);
$c_time_query="SELECT * FROM PICKUPTIME WHERE pickup_time_id=(SELECT pickup_time_id FROM DEST_PICKUP WHERE dest_id='$destination_id')";
$result=queryMysql($time_query);
?> <select name="pickup_name_select[]" size="5" multiple>
<?php
for($i=0; $i<$rows_timeslot_no; $i++)
{
$rows_timeslot_name=mysql_fetch_array($result);
$timeslot_id = $rows_timeslot_name['pickup_time_id'];
$timeslot_name=$rows_timeslot_name['pickup_time'];

echo "<option value= $timeslot_id>$timeslot_name</option>";
}
?>
</select>
<br />
<input   type= "submit"   name= "c_display_capacity"   value= "Display"> <br />
<input   type= "submit"   name= "c_delete"   value= "Delete">

</fieldset>
</div>
</form>
问题在表1和表3,当我打开这个页面的时候,表1和表3(这两个都是显示时间段)显示结果都是一样的,都是所有时间段。
但期望结果是,打开页面,只有表1(all timeslot)显示所有时间段,当选择表2中的地点之后,在表3里面显示出可用的时间段(current timeslot)。
这问题出在哪呢?谢谢!

解决方案 »

  1.   

    刚刚又试了一下,好像是我的SQL写错了?
    有没有高人啊!
    我把SQL里面的$destination_id改成4带进去,结果还是没变啊!
    这是为什么啊!
    高人在哪里?
      

  2.   

    queryMysql大概就是 mysql_query() 吧
    你查询到得结果不能直接用,需要 mysql_fetch_array()然后返回一个数组。
    而且你也你不用这么干
    while($row = mysql_fetch_array(//queryMysql返回的结果)
    {
    // 输出什么
    }
    等到指针到底了自然就也不会执行
      

  3.   

    主要是这一段<?php    
        $destination_id=$_POST['dest_name_select'][0]; //这个值拿到了,用echo显示是正确的
        $query_c_timeslot_no="SELECT COUNT(pickup_time_id) FROM DEST_PICKUP WHERE dest_id='$destination_id'";//我一直怀疑是不是我SQL写错了,因为我把$destination_id改成0带进去,结果一样。。
        $rows_timeslot_no=queryMysql($query_timeslot_no);
        $c_time_query="SELECT * FROM PICKUPTIME WHERE pickup_time_id=(SELECT pickup_time_id FROM DEST_PICKUP WHERE dest_id='$destination_id')";//我一直怀疑是不是我SQL写错了,因为我把$destination_id改成0带进去,结果一样。。
        $result=queryMysql($time_query);
    ?>    <select name="pickup_name_select[]" size="5" multiple>
    <?php
        for($i=0; $i<$rows_timeslot_no; $i++)
        {
            $rows_timeslot_name=mysql_fetch_array($result);
            $timeslot_id = $rows_timeslot_name['pickup_time_id'];
            $timeslot_name=$rows_timeslot_name['pickup_time'];
            echo "<option value= $timeslot_id>$timeslot_name</option>";
        }//这结果出来之后就像没有$destination_id这个限定条件似的。
    ?>        
            </select>到底哪错了?