我有两种带有 GET 方法的表单。当我提交第一个表单时,我得到了这个 URL
http://127.0.0.1/astronomy/student_enrollment.php?class_name_data=1&classNameGetDetails=
当我提交也有 GET 方法的第二个表单时。我的网址改成了这个
http://127.0.0.1/astronomy/student_enrollment.php?class_name_for_enrollment=Planet&sy_for_enrollment=2012-2013&sy_for_enrollment=45&number_of_student_enrolled=&time_schedule_student=Monday+to+Friday+8%3A00-9%3A00&generateFields=Generate
第一个查询字符串被删除并替换为第二个查询字符串
我希望我的网址看起来像这样
http://127.0.0.1/astronomy/student_enrollment.php?class_name_data=1&classNameGetDetails=&class_name_for_enrollment=Planet&sy_for_enrollment=2012-2013&sy_for_enrollment=45&number_of_student_enrolled=&time_schedule_student=Monday+to+Friday+8%3A00-9%3A00&generateFields=Generate
这两个查询字符串将结合分隔符 of &
and not ?
。我将如何做到这一点?
这是我的代码
<div class="enrollmentContent">
<div class="classNameChoices">
<label>Choose Class Name</label>
<form action="" method="get">
<select name="class_name_data">
<?php
$table = "classes";
$data = array(
'teacher_id' => $session_id
);
$class_name_query = show_filtered_rows($table, $data);
while($rows = mysql_fetch_array($class_name_query)){
$id = $rows['id'];
$class_name = $rows['class_name'];
?>
<option value="<?php echo $id; ?>"><?php echo $class_name; ?></option>
<?php
}
?>
</select>
<input type="submit" name="classNameGetDetails" value="" />
</form>
</div>
<?php
if(isset($_GET['classNameGetDetails'])){
$data2 = array(
'id' => $_GET['class_name_data'],
'teacher_id' => $session_id
);
$class_name_data_query = show_filtered_rows($table, $data2);
$rows_class = mysql_fetch_array($class_name_data_query);
?>
<div class="classDetailsByClassName">
<form action="" method="get">
<input type="hidden" value="<?php echo $rows_class['class_name']; ?>" name="class_name_for_enrollment" />
<input type="hidden" value="<?php echo $rows_class['school_year_from']."-".$rows_class['school_year_to']; ?>" name="sy_for_enrollment" />
<input type="hidden" value="<?php echo $rows_class['enrollees']; ?>" name="sy_for_enrollment" />
<label>Class Name <span><?php echo $rows_class['class_name']; ?></span></label>
<label>SY <span><?php echo $rows_class['school_year_from']."-".$rows_class['school_year_to']; ?></span></label>
<label>Maximum No. of Enrollees <span><?php echo $rows_class['enrollees']; ?></span></label>
<div class="registerDetails">
<div>
<label>Number of students to enroll</label>
<div><input type="number" name="number_of_student_enrolled" value=""/></div>
</div>
<div>
<label>Schedule</label>
<div>
<select name='time_schedule_student'>
<option value="Monday to Friday 8:00-9:00">Monday to Friday 8:00-9:00</option>
<option value="Monday to Friday 10:00-11:00">Monday to Friday 10:00-11:00</option>
<option value="Monday to Friday 1:00-2:00">Monday to Friday 1:00-2:00</option>
<option value="Monday to Friday 2:00-3:00">Monday to Friday 2:00-3:00</option>
<option value="Monday to Friday 9:00-10:00">Monday to Friday 9:00-10:00</option>
<option value="Monday to Friday 3:00-4:00">Monday to Friday 3:00-4:00</option>
</select>
</div>
</div>
<div><input type="submit" name="generateFields" value="Generate" /></div>
</div>
</form>
</div>
<div class="enrollmentFields">
<?php
if(isset($_GET['generateFields'])){
echo $_GET['class_name_for_enrollment'];
}
?>
</div>
<?php
}
?>
</div>
和我的功能
function show_filtered_rows($table, $data){
foreach($data as $fields=>$field_data){
$show_data[] = "`".$fields."` = '".$field_data."'";
}
return mysql_query("SELECT * FROM `$table` WHERE ".implode(" AND ",$show_data));
}