sonic 发表于 2010-9-8 16:47:32

class Model_name_model extends Model{

}

Hex 发表于 2010-9-8 16:48:00

你的 SQL 出错了吧。
你 echo $sql; 然后放到 phpmyadmin 试试,我觉得你的 sql 写错了,所以才报这个错。

sonic 发表于 2010-9-8 16:48:45

SQL语句错报的不是这个错吧。

ahkxhyl 发表于 2010-9-8 16:49:19

class Category extends Controller {

        function __construct(){
       
                parent::Controller();
               
                require_once('include.inc/application.php');
               
                //载入模型
                $this->load->model('category_model');
                $this->load->model('content_model');
               
        }



        /**
   * 页面详细信息
   *
   */
        function index(){
               
                //获取头部导航
                $data['top'] = 4;
               
                //获取参数
                $params = $this->uri->ruri_to_assoc();       
               
                $category = $params['id'];
               
                if($category==8){
                        $data['pr_year'] = $params['year'];
                }
               
                $data['category'] = $category;
                $data['category2'] = '';
               
                //left
                $data['news_left'] = $this->content_model->get_first(23);
                $data['year_list'] = $this->category_model->get_level_2(8);
这个是控制层

ahkxhyl 发表于 2010-9-8 16:50:20

class Category_model extends Model{

        function __construct(){
      parent::Model();
    }
function get_level_2($category){
                $sql = "select * from category where category='$category' order by Id desc";
                $query = $this->db->query($sql);
                $rows = array();
                $array = $query->result_array();
      foreach ($array as $row){
            $rows[] = $row;
      }
      return $rows;
        }
}
这个是模型层

sonic 发表于 2010-9-8 16:51:35

'$category' 单引号?

ahkxhyl 发表于 2010-9-8 16:51:41

echo $sql里面有值
echo $query 空白的

sonic 发表于 2010-9-8 16:52:44

因为你单引号了

sonic 发表于 2010-9-8 16:53:16

你用?代替变量
然后用$res=$this->db->query($sql,array(?));

sonic 发表于 2010-9-8 16:56:27

再不行用PHP底层函数

$cate_id=(int)$this->cate_id();

$sql="select * from category where cate_id=$cate_id";
$res=mysql_query($sql);

while($row=mysql_fetch_array($res))
{
   $rows[]=$row;
}
页: 1 [2] 3 4
查看完整版本: 急!求助CI高手