gpt4 book ai didi

php - 动态下拉列表在每个项目之前显示短语

转载 作者:行者123 更新时间:2023-11-29 21:50:06 26 4
gpt4 key购买 nike

我创建了此表单,它使用第一个选项select加载动态下拉列表,但它在每个列表项之前显示选项select

<div class="form-group">
<label class="col-sm-3 control-label">
<?php echo get_phrase( 'teacher');?>
</label>
<div class="col-sm-5">
<select name="teacher_id" class="form-control select2" style="width:100%;">
<?php $teachers=$ this->db->get('teacher')->result_array(); foreach($teachers as $row): ?>
<option value="">
<?php echo get_phrase( 'select');?>
</option>
<option value="<?php echo $row['teacher_id'];?>">
<?php echo $row[ 'name'];?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>

函数 get_phrase:

if ( ! function_exists('get_phrase')){

function get_phrase($phrase = '') {
$CI =& get_instance();
$CI->load->database();
$current_language = $CI->db->get_where('settings' , array('type' => 'language'))->row()->description;

if ( $current_language == '') {
$current_language = 'english';
$CI->session->set_userdata('current_language' , $current_language);
}


/** insert blank phrases initially and populating the language db ***/
$check_phrase = $CI->db->get_where('language' , array('phrase' => $phrase))->row()->phrase;
if ( $check_phrase != $phrase)
$CI->db->insert('language' , array('phrase' => $phrase));


// query for finding the phrase from `language` table
$query = $CI->db->get_where('language' , array('phrase' => $phrase));
$row = $query->row();

// return the current sessioned language field of according phrase, else return uppercase spaced word
if (isset($row->$current_language) && $row->$current_language !="")
return $row->$current_language;
else
return ucwords(str_replace('_',' ',$phrase));
}
}

感谢您的帮助。

最佳答案

试试这个

   <div class="form-group">
<label class="col-sm-3 control-label"><?php echo get_phrase('teacher');?></label>
<div class="col-sm-5">
<select name="teacher_id" class="form-control select2" style="width:100%;">
<option value=""><?php echo get_phrase('select');?></option>
<?php
$teachers = $this->db->get('teacher')->result_array();
foreach($teachers as $row):
?>
<option value="<?php echo $row['teacher_id'];?>"><?php echo $row['name'];?></option>
<?php
endforeach;
?>
</select>
</div>
</div>

关于php - 动态下拉列表在每个项目之前显示短语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33729919/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com