[英]how to set the value of selected dropdown in php?
I am trouble to set the value of selected option value in PHP. 我很难在PHP中设置所选选项的值。 At the time of fetching data in MySQL i haven't set the selected value of dropdown in PHP.
在MySQL中获取数据时,我尚未在PHP中设置dropdown的选定值。
function get_document_name($documents_name)
{
$output = "";
foreach ($documents_name as $small_letter => $cap_letter) {
$selected = ($document_name == $cap_letter) ? 'selected' : '';
$output .= "<option value='".$small_letter."'".$selected.">".$cap_letter."</option>";
}
return $output;
}
Try using below solution. 尝试使用以下解决方案。 If your if condition doesn't matches, then display normal select option and if matches, then show selected.
如果您的if条件不匹配,则显示正常选择选项,如果匹配,则显示selected。
function get_document_name($documents_name)
{
$output = "";
foreach ($documents_name as $small_letter => $cap_letter)
{
if( $document_name != $cap_letter )
{
$output .= "<option value='".$small_letter."'>".$cap_letter."</option>";
}
else
{
$output .= "<option value='".$small_letter."' 'selected'='selected'>".$cap_letter."</option>";
}
}
return $output;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.