0

在下面的代码中,列表框正在填充值,但是当我选择相应的列表值并单击搜索时,表格没有显示。我在这里使用 SELF_PHP 进行表单操作,这个表单的想法是在加载页面时列表将被填充并且 id 被填充。当我选择一个列表值并单击搜索按钮时,它应该只显示在列表框中选择的救护车 ID 或 ID 的值的表格。请帮我。

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
             <meta charset="utf-8">
                <title>TPS Login Page</title>
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
            </head>
            <body>  
            <center>
            <h2>Ambulance Activity Log</h2>
            <hr>
             <form name="search" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

             View activity of ambulance:   
             <Select NAME="field">
              <?php 
                include 'con.php';
                $query = "SELECT amb_id FROM ambulance;";
                $result = mysql_query($query) or die("Unable to retreive amb_id :".mysql_error()); 

                if(mysql_num_rows($result) > 0)
                {
                  while($row = mysql_fetch_array($result)) 
                  {
                    echo"<option id=\"ambid\" value=$row[amb_id]>$row[amb_id]</option>";
                  }
                }
              ?>
             </Select>
             <input class="btn btn-info" type="submit" name="search" value="Search" />
             <input type="hidden" name="searching" value="yes" />

             </form>

            <?php
            if(isset($_POST['submit'])) 
            {
                $id=getElementById('ambid') ;

                $query = "SELECT * FROM log WHERE amb_id='$id' ORDER BY l_time DESC;";
                $result = mysql_query($query) or die(mysql_error()); 
                print " 
                <table border=\"5\" cellpadding=\"5\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#808080\" width=\"800\" text-align=\"center\" id=\"AutoNumber2\" bgcolor=\"#C0C0C0\">
                <tr>            
                <td width=\"30\">Amb ID</td> 
                <td width=\"120\">Event Time</td> 
                <td width=\"50\">Description</td> 
                <td width=\"30\">Signal ID</td> 
                <td width=\"30\">Road No</td> 
                <td width=\"30\">Priority</td> 
                </tr>"; 

                while($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
                { 
                print "<tr>"; 
                print "<td>" . $row['amb_id'] . "</td>"; 
                print "<td>" . $row['l_time'] . "</td>"; 
                print "<td>" . $row['l_event'] . "</td>";
                print "<td>" . $row['t_sigid'] . "</td>";
                print "<td>" . $row['l_roadno'] . "</td>";
                print "<td>" . $row['e_priority'] . "</td>";

                print "</tr>"; 
                } 
                print "</table>"; 
                print "</center>";
            }
            ?>
           </body>
            </html>

请帮我。提前致谢 :)

4

1 回答 1

0

<select>标签一个更好的名字。并引用您的"$row[amb_id]". value=$row[amb_id]!是错的。

<select name="ambid" size="10">
....

              {
                echo"<option value=\"$row[amb_id]\">$row[amb_id]</option>";
              }
 </select>

发布后,您可以通过以下方式获得它:

  if(isset($_POST['submit'])) 
    {
     $id=$_POST['ambid'];
     $query = "...
于 2013-05-06T20:01:09.997 回答