如何在重定向的php页面中使用下拉数据作为参考?

时间:2016-11-03 16:24:03

标签: php

我有很多PHP页面,我已经启动了一个,我还有一个包含数据库下拉菜单的php页面。

现在我想使用我当前页面下拉列表中选择的数据作为填充下一页的下拉列表的参考,但我不知道如何做到这一点:这是我的第一个php页面的代码:

enter  <form method = "get" action = "register.php">
  <label>Choose Department:</label><br>
   <select name = "select" class= "textfields" id= "">

       <option id = "">Choose department</option>

   <?php
   //connect to db 
  $connect = mysqli_connect('localhost', 'root', '', 'guu portal') or die ('cant you just connect to the database');                  

  $query = "select * from departments";
  $result = mysqli_query($connect,$query);

  while($row = mysqli_fetch_array($result)){  
      $take = $row['id'] ;                
 ?>       
  <option id = "<?php echo $take; ?>"><?php echo $row['departments']; ?></option>
  <?php } 
  ?>

   
   
             

这里

现在dis正在工作,我想在这个其他页面中使用$ take作为参考,这里是代码:

enter  <form class= "form" role = "form" method="post" action=""> 
         <fieldset><legend>Course Registration</legend> <div class = "col-sm-12"><label>code</label><select name ="select"> <option id ="">choose</option>








<?php 
$connect = mysqli_connect('localhost', 'root', '', 'guu portal') or die ('cant you just connect to the database');

$query = "select * from registration";

$result = mysqli_query($connect,$query); 

while($row = mysqli_fetch_array($result)){ 
?>
<option id = "<?php echo $row['departments'];?>"><?php echo $row['course_code']; ?></option>
<?php }
?> 
</select>

<label>title</label>
<select name= "select"> 
<option id ="">---</option>
<?php $query = "select * from registration";
$result = mysqli_query($connect,$query); 

while($row = mysqli_fetch_array($result)){ 
 ?>
<option id = "<?php echo $row['departments'];?>"><?php echo $row['title']; ?></option>          
<?php }
?>
</select>

<label>unit</label>
<select name= "select"> 
<option id ="">---</option>
<?php $query = "select * from registration";
$result = mysqli_query($connect,$query); 
while($row = mysqli_fetch_array($result)){ 
?>
<option id = "<?php echo $row['departments'];?>"><?php echo $row['unit']; ?></option>          
<?php }
?>
</select>  

这里

所以我该怎么做?

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您正试图将$ row [&#39; departments&#39;]传递给第二个文件。

您可以使用ajax调用或通过url传递它。