[英]dropdown list not getting populated in CI
I am designing application using CI. 我正在使用CI设计应用程序。 and want to show the drop down however its not displaying it.
并想显示下拉菜单,但不显示它。 View
视图
<label>Select Customer</label>
<select name="name" id="name" class="form-control" required="true">
<option selected="">Select Customer</option>
<?php if(isset($client_name)) {
//var_dump($name);
foreach($client_name as $tn)
{
$tn=(array)$tn;
echo '<option selected="" value="'.$tn['name'].'" >'.$tn['name'].'</option>';
//echo '<option selected="" value="'.$tn['tid'].'" >'.$tn['tname'].'</option>';
}
}
else{
echo '<option selected="" value="Data Not found" >Error</option>';
}
?>
</select>
Model: 模型:
public function fetch_client(){
$this->db->select('name');
$this->db->distinct();
$this->db->from($this->table);
$query = $this->db->get();
return $query->result();
}
Controller 控制者
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Invoice extends CI_Controller {
public function __construct()
{
parent::__construct();
//$this->load->model('person_model','person');
$this->load->model('client_model','client');
}
public function index()
{
$this->load->helper('url');
//$this->load->view('person_view');
$data['client_name']=$this->client->fetch_client();
$this->load->view('createinvoice',$data);
}
}
The front end is only displaying Error saying data not found. 前端仅显示错误,提示未找到数据。 Not sure where I am going wrong.
不知道我要去哪里错了。 Please help !!!
请帮忙 !!!
1.Check the query 1.检查查询
var_dump($this->db->last_query());
2.Check the value in Controller 2.检查控制器中的值
var_dump($data['client_name']);
3.Check the route is correct or not? 3.检查路线是否正确?
route["my-controller/my-method"] = "Invoice/index";
Edit this 编辑这个
if(isset($client_name))
to 至
if(isset($client_name) && !empty($client_name))
then remove 然后删除
selected=""
edit this 编辑这个
$this->db->distinct();
to 至
$this->db->distinct('id');
if you want use distinct. 如果您想使用与众不同。 you can change "id" to "name" if your table don't use id
如果表不使用id,则可以将“ id”更改为“ name”
Try This Code : Controller <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Invoice extends CI_Controller { public function __construct() { parent::__construct(); //$this->load->model('person_model','person'); $this->load->model('client_model','client'); } public function index() { $this->load->helper('url'); //$this->load->view('person_view'); $fetch_record['client_name'] = $this->Model->select('city'); $this->load->view('createinvoice',$fetch_record); } } Model public function fetch_client($table){ $this->db->distinct(); $this->db->select('name'); $this->db->from($table); $r= $this->db->get($table); $res = $r->result(); return $res; } View <label>Select Customer</label> <select name="name" id="name" class="form-control" required="true"> <option selected="">Select Customer</option> <?php if(!empty($client_name)) { //var_dump($name); foreach ($client_name as $c) { ?> <option value="<?php echo $c->name ?>"><?php echo $c->name; ?></option> <?php } } else { echo '<option selected="" value="Data Not found" >Error</option>'; } ?> </select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.