我有兩種形式的GET方法。當我提出第一個形式,我得到這個URLPHP使用兩種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
去除第一查詢字符串,並以第二查詢字符串
我希望我的URL看起來像這樣
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
兩個取代查詢字符串將與&
的分隔符組合,而不是?
。我將如何做到這一點?
這是我的代碼
<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));
}