我想從從數據庫檢索的值列表中選擇單個值。問題是,當用戶類型假設f,並且數據庫中有2個或多於2個值時,則在該字段上可以看到
標籤。我應該如何刪除在值之間顯示的br。請幫忙。如何讓用戶從輸入字段下方回顯的值列表中選擇單個值
控制器PAGE-> admin_c.php
public function get_values_c()
{
$e_name = $_REQUEST['ename'];
$res = $this->admin_m->get_ename_m($e_name);
if(sizeof($res)>0)
echo implode("</br>",$res);
}
模型PAGE-> admin_m.php
public function get_ename_m($e_name)
{
$ename_value = [];
if($e_name!="")
{
$sql = "select distinct ename from event where ename like '$e_name%'";
$res = $this->db->query($sql);
foreach($res->result_array() as $row)
{
$ename_value[] = $row['ename'];
}
return $ename_value;
}
}
視圖PAGE-> edit_event.php
<div class="control-group" style="margin-bottom:10px;">
<label class="control-label" style="margin-left:-64px;">Event Name</label>
<div class="controls" style="margin-left:28%">
<input type="text" class="span11" placeholder="Event name" name="ename" id="ename" style="width:95% !important;margin-left: -28px !important;">
<span class="span11" id="show_ename" style="display:none;width:95% !important;margin-left: -28px !important;background-color:white;font-size:15px;"></span>
</div>
</div>
Ajax代碼在查看頁碼:
$('#ename').keyup(function(){
$.ajax({
url:'<?php echo site_url()."/admin_c/get_values_c";?>',
method:'post',
data:{'ename':$(this).val()},
success: function(res,res1){
$('#show_ename').show();
$('#show_ename').html('');
$('#show_ename').html(res);
}
});
});
$('#show_ename').click(function(){
var ename_value = $(this).html();
$('#ename').val(ename_value);
$(this).html('');
$(this).hide();
});
無效HTML''有效HTML'
'或''
仍然 – RiggsFolly
相同的輸出.. – Unnati
檢查[這裏](https://www.youtube.com/watch?v=J6REieQ1SyA&list = PLfdtiltiRHWGJA_SN2O9t5DSlz7PTwAru)如何在普通的PHP之外創建它。然後將其轉換爲CI。 – Tpojka