|
本帖最后由 liaomars 于 2011-3-9 00:06 编辑
大家帮忙看下.这个问题.我在控制器里重复调用了模型里的一个方法.第一个调用可以读取数据.第二次调用读取不了数据.请问这是什么原因.在这谢谢大家了!
这是控制器的代码PHP复制代码 function index() { $this->load->Model('admin/Admin_model');
$data['head'] = 'head';
$data['foot'] = 'foot';
$data['right'] = 'right';
$data['row'] = $this->Admin_model->read_index(1, 1, 10);
$data['row_qiugou'] = $this->Admin_model->read_index(2, 1, 10);
$this->load->view('index', $data);
} 复制代码 这是模型代码PHP复制代码 <?php
class Admin_model extends Model {
function __construct () {
parent ::Model();
$this->load->database();
date_default_timezone_set('Asia/Shanghai'); //设置时区
}
function insert () {
$addtime = mktime();
$data = array(
'deal_title' => $this->input->xss_clean($this->input->post('deal_title')),
'deal_type' => $this->input->xss_clean($this->input->post('deal_type')),
'deal_cate' => $this->input->xss_clean($this->input->post('deal_cate')),
'deal_time' => $this->input->xss_clean($this->input->post('deal_time')),
'deal_price' => $this->input->xss_clean($this->input->post('deal_price')),
'deal_address' => $this->input->xss_clean($this->input->post('deal_address')),
'tel' => $this->input->xss_clean($this->input->post('tel')),
'contact' => $this->input->xss_clean($this->input->post('contact')),
'other_contact' => $this->input->xss_clean($this->input->post('other_contact')),
'deal_des' => $this->input->xss_clean($this->input->post('FCKeditor1')),
'deal_state' => $this->input->xss_clean($this->input->post('deal_state')),
'add_time' => $addtime
);
$this->db->insert('deal', $data);
}
function read_index ($type,$state,$limit){
$query = $this->db->query('SELECT * FROM deal WHERE deal_type='.$type.' AND deal_state='.$type.' LIMIT '.$limit.'');
return $query;
}
}
?>
复制代码
这是视图代码HTML复制代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>换手网 </title>
<base href="<?php echo base_url(); ?>"> </base>
<link href="style/css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php $this->load->view($head); ?>
<div class="lm_1 w800">
<div class="lanmu_1">
<dl>
<dt>物品转让 </dt>
<?php
foreach($row->result_array() as $rs){
?>
<dd><?php echo mb_substr($rs['deal_title'], 0, 20, 'utf-8');?></dd>
<?php }?>
</dl>
</div>
<div class="lanmu_1">
<dl>
<dt>求购信息 </dt>
<?php
foreach($row_qiugou->result_array() as $rs_qg){
?>
<dd><?php echo mb_substr($rs_qg['deal_title'], 0, 20, 'utf-8');?></dd>这个地方是空的.没有读出数据.也没有报错
<?php }?>
</dl>
</div>
</body>
</html>
复制代码 |
|