PHP 从数据库提交后保留下拉值
PHP Keep drop down value after submitting from database
我想在更改提交后保留我的下拉值。
HTML代码
<select id="Doctor" name="Doctor" onchange="this.form.submit();">
<?php
$Store->displayDoctors()
?>
</select>
PHP代码
public function displayDoctors(){
$sql = "SELECT * FROM doctor";
$result = @mysqli_query($this->conn, $sql);
while($data = mysqli_fetch_array($result))
{
echo "<option value='". $data['docID'] ."'>" .$data['FirstName']." ".$data['LastName'] ."</option>";
}
}
我想你可以这样使用:
HTML:
<select id="Doctor" name="Doctor" onchange="this.form.submit();">
<?php
$Store->displayDoctors($_REQUEST['Doctor'])
?>
</select>
PHP:
public function displayDoctors($value=false){
$sql = "SELECT * FROM doctor";
$result = @mysqli_query($this->conn, $sql);
while($data = mysqli_fetch_array($result))
{
$selected="";
if($data['docID']==$value)
{
$selected="selected";
}
echo "<option value='". $data['docID'] ."' $selected>" .$data['FirstName']." ".$data['LastName'] ."</option>";
}
}
我想在更改提交后保留我的下拉值。
HTML代码
<select id="Doctor" name="Doctor" onchange="this.form.submit();">
<?php
$Store->displayDoctors()
?>
</select>
PHP代码
public function displayDoctors(){
$sql = "SELECT * FROM doctor";
$result = @mysqli_query($this->conn, $sql);
while($data = mysqli_fetch_array($result))
{
echo "<option value='". $data['docID'] ."'>" .$data['FirstName']." ".$data['LastName'] ."</option>";
}
}
我想你可以这样使用: HTML:
<select id="Doctor" name="Doctor" onchange="this.form.submit();">
<?php
$Store->displayDoctors($_REQUEST['Doctor'])
?>
</select>
PHP:
public function displayDoctors($value=false){
$sql = "SELECT * FROM doctor";
$result = @mysqli_query($this->conn, $sql);
while($data = mysqli_fetch_array($result))
{
$selected="";
if($data['docID']==$value)
{
$selected="selected";
}
echo "<option value='". $data['docID'] ."' $selected>" .$data['FirstName']." ".$data['LastName'] ."</option>";
}
}