pary_daryayi
شنبه 10 خرداد 1393, 12:21 عصر
سلام . من همیشه از active record در CI استفاده میکنم . اما الان تو این کوئری خاص نمیدونم چطور ازش استفاده کنم :
SELECT SUBSTR(newdate, 1, 4) as year FROM (`m_article`)
اینطور استفاده کردم ولی جواب نداد :
model:
public function fetch_tb($tb,$filde,$where=NULL){
$this->db->select($filde);
if(!is_null($where)){
$this->db->where($where);
}
$result = $this->db->get($tb);
return $result;
}
controller:
public function select_section(){
$field="SUBSTRING(newdate, 1, 4) as year";
$data['res']=$this->article_model->fetch_tb('m_article',$field);
$this->_out('admin','article','res',$data);
}
view:
foreach($res as $v){ echo $v->year,'<br>';}
خطایی که میده اینه :
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as year FROM (`m_article`) ORDER BY `id` ASC' at line 1
SELECT SUBSTR(newdate, `1`, `4)` as year FROM (`m_article`) ORDER BY `id` ASC
Filename: C:\xampp\htdocs\mysite\m-blog\system\database\DB_driver.php
Line Number: 330
SELECT SUBSTR(newdate, 1, 4) as year FROM (`m_article`)
اینطور استفاده کردم ولی جواب نداد :
model:
public function fetch_tb($tb,$filde,$where=NULL){
$this->db->select($filde);
if(!is_null($where)){
$this->db->where($where);
}
$result = $this->db->get($tb);
return $result;
}
controller:
public function select_section(){
$field="SUBSTRING(newdate, 1, 4) as year";
$data['res']=$this->article_model->fetch_tb('m_article',$field);
$this->_out('admin','article','res',$data);
}
view:
foreach($res as $v){ echo $v->year,'<br>';}
خطایی که میده اینه :
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as year FROM (`m_article`) ORDER BY `id` ASC' at line 1
SELECT SUBSTR(newdate, `1`, `4)` as year FROM (`m_article`) ORDER BY `id` ASC
Filename: C:\xampp\htdocs\mysite\m-blog\system\database\DB_driver.php
Line Number: 330