php CI 框架如何从数据库中取值(一个二维数组)以表格的形式显示到view层!
model层中已经有方法functionget_report_item($competition_id,$report_class){$sql='SELECTreport...
model层中已经有方法
function get_report_item($competition_id, $report_class){
$sql = 'SELECT report_item_no,report_item_content,report_item_content_easy,report_item_class FROM t_report_item where competition_id = ? and del_flg = ?';
$val = array($competition_id, $this->config->item('del_flg_off'));
if($report_class == '02'){
$sql = $sql.' and report_class = ? ';
$val['report_class']=$report_class;
//$val['light_report_flg']=0;
}else if($report_class == '04'){
$sql = $sql.' and report_class = ? and light_report_flg = ?';
$val['report_class']='02';
$val['light_report_flg']=1;
}else{
$sql = $sql.' and report_class = ?';
$val['report_class']=$report_class;
}
$query = $this->execute($sql, $val);
return $query;
}
再控制层要怎么写呢?还有view层要如何写才能显示出来? 展开
function get_report_item($competition_id, $report_class){
$sql = 'SELECT report_item_no,report_item_content,report_item_content_easy,report_item_class FROM t_report_item where competition_id = ? and del_flg = ?';
$val = array($competition_id, $this->config->item('del_flg_off'));
if($report_class == '02'){
$sql = $sql.' and report_class = ? ';
$val['report_class']=$report_class;
//$val['light_report_flg']=0;
}else if($report_class == '04'){
$sql = $sql.' and report_class = ? and light_report_flg = ?';
$val['report_class']='02';
$val['light_report_flg']=1;
}else{
$sql = $sql.' and report_class = ?';
$val['report_class']=$report_class;
}
$query = $this->execute($sql, $val);
return $query;
}
再控制层要怎么写呢?还有view层要如何写才能显示出来? 展开
展开全部
控制层
function test_func(){
//获取model页面需要的两个参数
$competition_id = $_GET["competition_id"];
$report_class = $_GET["report_class"];
$this->load->model("Action"); //引入model
$data["head"] = $this->Action->get_report_item($competition_id, $report_class); //引用model的函数
$this->load->view("test_result",$data); //将结果显示在test_result.php页面中
}
view层:
<div id='result_div'>
<h3 style="align:center;color:blue;">添加结果显示</h3>
<?php if ($head){?> //此处选择了循环输出从控制层传输的结果
<table align="center"; border="1" cellpadding="1" cellspacing="1">
<tr align="center">
<td>字段名称(含义)</td> //该td中显示的是你从数据库、即model层中获取到的数据的含义,想显示多少,显示哪个,在这里确认
</tr>
<?php foreach ($head as $item){ ?>
<tr align="center">
<td><?php echo $item->test; ?></td>
</tr>
</table>
<?php }else {
echo “123”;
}?>
</div>
function test_func(){
//获取model页面需要的两个参数
$competition_id = $_GET["competition_id"];
$report_class = $_GET["report_class"];
$this->load->model("Action"); //引入model
$data["head"] = $this->Action->get_report_item($competition_id, $report_class); //引用model的函数
$this->load->view("test_result",$data); //将结果显示在test_result.php页面中
}
view层:
<div id='result_div'>
<h3 style="align:center;color:blue;">添加结果显示</h3>
<?php if ($head){?> //此处选择了循环输出从控制层传输的结果
<table align="center"; border="1" cellpadding="1" cellspacing="1">
<tr align="center">
<td>字段名称(含义)</td> //该td中显示的是你从数据库、即model层中获取到的数据的含义,想显示多少,显示哪个,在这里确认
</tr>
<?php foreach ($head as $item){ ?>
<tr align="center">
<td><?php echo $item->test; ?></td>
</tr>
</table>
<?php }else {
echo “123”;
}?>
</div>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询