我正在编写一个模块,我必须在其中打印类别。
为此,我首先编码以过滤您要搜索的基础(ID / NAME),然后根据用户选择的这些信息,动态创建一个选择列表。
这是问题所在:这个动态创建的选择列表,我想在表单字段中打印它的相关数据(使用 where 子句)。我没有得到现场的回声。其余部分(动态选择列表框)正在出现;
这是我的看法:
<div class="navbar">
<div class="navbar-inner">
<h2>Show Category</h2>
<?php
$dropdown_category= array(
'c_id'=>'Category Code',
'c_name'=>'Category Name');
echo form_dropdown('clas',$dropdown_category,'','id="clas"');
?>
<div id="name_sec">
<!-- PRONT DROP DOWN HERE !-->
</div>
</div>
<br/>
<div class="navbar-inner">
<br/>
<div id="name_sec2">
<!-- PRONT form fields HERE !-->
</div>
</div>
<div class="navbar"></div>
</div>
我的控制器:
public function category_display()
{
//Checking so that people cannot go to the page directly.
$this->load->helper('form');
$this->load->database();
$tabel_for_this="its_category";
$data_toprint='';
$id=$this->input->post('send_data_post');
$query = $this->db->query("SELECT ".$id." FROM ".$tabel_for_this." ");
foreach ($query->result_array() as $r)
{
$dropdown_category2[$r[$id]] = $r[$id];
}
echo form_dropdown('clas2',$dropdown_category2,'','id="clas2"');
}
public function category_display_in_fields()
{
$this->load->helper('form');
$this->load->database();
$tabel_for_this="its_category";
$data_toprint='';
$id=$this->input->post('send_data_post_for_field');
$sql = "SELECT * FROM ".$tabel_for_this." where '".$id."'= ?";
$query = $this->db->query($sql,$id);
foreach ($query->result_array() as $r)
{
echo '<input type="text" name="c_dateadded" placeholder="Date" value>
<input type="text" name="'.$r['c_id'].'" placeholder="'.$r['c_name'].'" value>
<select name="c_addedby" placeholder="Added By" value>
<option>added by</option><option>name1</option><option>name2</option><option>name3</option><option>name4</option>
</select>
<input type="text" name="c_description" placeholder="Description" value>
<input type="text" name="i_nos." placeholder="Total Items No." value>
<input type="text" name="c_i_nos_avail" placeholder="Available Stock" value> ';
}
}
这是我的js:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#clas").change(function(){
var send_data=$("#clas").val();
$.ajax({
type:"post",
url:"category_display",
data:"send_data_post="+send_data,
success:function(data){
$("#name_sec").html(data);
}
});
});
});
</script>
<!-- CODE TO PRINT DATA IN FIELDS!-->
<script type="text/javascript">
$(document).ready(function(){
$("#clas2").change(function(){
var send_data2=$("#clas2").val();
$.ajax({
type:"post",
url:"category_display_in_fields",
data:"send_data_post_for_field="+send_data2,
success:function(data2){
$("#name_sec2").html(data2);
}
});
});
});
</script>
仅出于测试目的,我在控制器中编写了与数据库相关的内容