例如我有数据库:
id | Code | Name | Age |
==============================
1 | 111 | AAAA | 21 |
2 | 121 | BBBB | 23 |
和sql查询代码:
public function detail($Code)
{
$tSQL = "select * from table_employee where Code = '{$Code}' ";
$query = $this->db->query($tSQL);
return $query->num_rows();
}
如何在视图中显示
<?php
if( !empty($detail) ) { foreach($detail as $row) { ?>
<?php echo "<tr>" ?> <?php echo "<td width='1%'><center>".$row->code;"<center></td>" ?>
<?php echo "<td width='1%'><center>".$row->name;"<center></td>"?>
<?php echo "<td width='1%'><center>".$row->age;"<center></td>"?>
<?php }} ?>
从任何人都知道的情况来看?
答案 0 :(得分:0)
在视图中,您只需要使用标记到您的php语法
<?php
if(!empty($detail) ) {
foreach($detail as $row) { ?>
<tr>
<td width='1%'><center><?php echo $row->code;?> <center></td>
<td width='1%'><center><?php echo $row->name;?> <center></td>
<td width='1%'><center><?php echo $row->age;?><center></td>
</tr>
<?php }} ?>
答案 1 :(得分:0)
尝试一次......
控制器..
public function detail($Code)
{
$this->db->where('Code',$Code);
$data = $this->db->get('table_employee')->result();
return $data;
}
在视图中
foreach($data as $row) { ?>
<tr>
<td width='1%'><center><?php echo $row->code;?> <center></td>
<td width='1%'><center><?php echo $row->name;?> <center></td>
<td width='1%'><center><?php echo $row->age;?><center></td>
</tr>
<?php } ?>