<select name='test'>
<option value='north' india>north india</option>
<option value='goa'>goa</option>
</select>
如果我选择&#34;北印度&#34;在列表PHP回声只&#34;北&#34;。那是为什么?
此HTML由以下PHP代码生成:
$cond_city= "WHERE state=? GROUP BY cityName ORDER BY cityName ASC";
$data_city= array($state);
$select_city=$this->select_rows(TABLEPREFIX.'region','*',$cond_city,$data_city);
while($arr_city=$select_city->fetch(PDO::FETCH_ASSOC)){
echo '<option value='.$arr_city['cityName'].'>'.$arr_city['cityName'].'</option>';
}
答案 0 :(得分:4)
在您的代码中,value
等于'north'
,因为您错放了引号:
<option value='north' india>north india</option>
你需要这个:
<option value='north india'>north india</option>
要获得此结果,您需要在PHP代码中添加引号,如下所示:
<?php
$cond = "WHERE state=? GROUP BY cityName ORDER BY cityName ASC";
$data = array($state);
$select=$this->select_rows(TABLEPREFIX.'region','*',$cond_city,$data_city);
while ($arr_city=$select_city->fetch(PDO::FETCH_ASSOC)) {
echo '<option value="'.$arr_cit.' '.$sel_cnt.' >'.$arr_city['cityName']."'</option>';
}
?>
答案 1 :(得分:0)
因为您已将选项的值设置为“北”。如果你想要'北印度'整体,那么替换下面的代码。
<select name='test'>
<option value='north india'>north india</option>
<option value='goa'>goa</option>
</select>
答案 2 :(得分:0)
它正在发生,因为当您提交数据时,您对输入的名称(select
在您的情况下)有价值。要获得所需的值,您应该在select的value
属性中指明它。
<select name='test'>
<option value="north india">North India</option>
</select>