如何通过在下拉列表中选择并在表中显示来获取所有项目名称


function fetchdetails() {
var item = $('#Item').val();
$.ajax({
type: "POST",
url: "<?php echo base_url();?>TipUp_Loan/item_fetch",
data: {
item: item
},
datatype: 'json',
success: function (data) {
var json = data,
obj = 
JSON.parse(json);
//var prodName =  
$(e).closest('tr').find('#Product_Name');
//$(prodName).val(obj.itemname);
$(this).('#Product_Name').val(obj.itemname);
}
});
}

这是一个脚本代码。。。

public function fetch_item($item)
{
$this->db->where("pgroup",$item);
$this->db->select('*');
$this->db->from('itemmaster');
$this->db->join('pgroup','pgroup.pgroupid = itemmaster.catcode','left outer');
$query = $this->db->get()->row();
return $query;
}

这是型号代码。。。我的prblm是如何通过select获取数据在下拉列表中并显示在表中。现在i我在表中有4个项目名称,它只能提取1个名称,但它不显示所有项目名称。。。

首先,您的查询有问题,这是查询解决方案:

public function fetch_item($item)
{
$this->db->where("pgroup",$item);
$this->db->select('*');
$this->db->from('itemmaster');
$this->db->join('pgroup','pgroup.pgroupid = itemmaster.catcode','left outer');
$query_result = $this->db->get()->result();
//pass query result as html
$output = '<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Product Name</th>
</tr>
</thead>
<tbody>';
if($query_result !='false'){
foreach ($query_result as $key => $value) {
$output .='<tr>
<td>'.$value->product_name.'</td>
</tr>';
}
}
$output .="</tbody>
</table>";
echo $output;
}

在将上述查询结果返回到脚本之后。然后,在将数据传递到产品选择标签之前,您必须设置一个forloop

以下是更改后的ajax调用:

function fetchdetails()
{
var item = $('#Item').val();
$.ajax({
type: "POST",
url: "<?php echo base_url();?>TipUp_Loan/item_fetch",
data: {item:item},
cache: true,
datatype: 'json',
success: function (data) {
$('#Product_Name_div').html(data);              
}
});
}

这是查看文件产品列表显示代码

<div id="Product_Name_div">
</div>

最新更新