CodeIgniter Forums
how to solve this db error? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: how to solve this db error? (/showthread.php?tid=64964)



how to solve this db error? - waptik - 04-14-2016

I am trying to list statistics about my contents.
I have these tables{(sms:id,status,like,user,sms); (like_today:id,sms_id,vote,date); (like_history:id,sms_id,vote,date) }

This is my php code:

$this->db->select("*")->from("sms");
$this->db->where('sms.status', 'A');
if($day=='today'){
$this->db->select("COUNT('like_today.sms_id') as vote");
$this->db->join('id', 'sms.id = like_today.sms_id', 'LEFT');
$this->db->group_by('like_today.sms_id');
}else{
$this->db->select("COUNT('like_history.vote') as vote");
if($day=='yesterday')
$this->db->where('like_history.date', date('Ymd',strtotime('-1 day')));
if($day=='week')
$this->db->where('like_history.date >', date('Ymd',strtotime('-1 week')));
if($day=='month')
$this->db->where('like_history.date >', date('Ymd',strtotime('-1 month')));
$this->db->join('id', 'sms.id = like_history.sms_id', 'LEFT');
$this->db->group_by('like_history.sms_id');
}
$this->db->order_by('vote', "DESC");
$c = $this->db->get();

and this the error i get :
A Database Error Occurred
Error Number: 1142
SELECT command denied to user 'db_name'@localhost for table 'id'
SELECT *, COUNT('like_today.sms_id') as vote FROM `sms` LEFT JOIN `sms`.`id` ON `sms`.`id` = `like_today`.`id` WHERE `sms`.`status` = 'A' GROUP BY `like_today`.`sms_id` ORDER BY `vote` DESC . Any help?


RE: how to solve this db error? - jonathanq - 04-14-2016

(04-14-2016, 01:36 PM)waptik Wrote: I am trying to list statistics about my contents.
I have these tables{(sms:id,status,like,user,sms); (like_today:id,sms_id,vote,date); (like_history:id,sms_id,vote,date) }

This is my php code:

$this->db->select("*")->from("sms");
$this->db->where('sms.status', 'A');
if($day=='today'){
$this->db->select("COUNT('like_today.sms_id') as vote");
$this->db->join('id', 'sms.id = like_today.sms_id', 'LEFT');
$this->db->group_by('like_today.sms_id');
}else{
$this->db->select("COUNT('like_history.vote') as vote");
if($day=='yesterday')
$this->db->where('like_history.date', date('Ymd',strtotime('-1 day')));
if($day=='week')
$this->db->where('like_history.date >', date('Ymd',strtotime('-1 week')));
if($day=='month')
$this->db->where('like_history.date >', date('Ymd',strtotime('-1 month')));
$this->db->join('id', 'sms.id = like_history.sms_id', 'LEFT');
$this->db->group_by('like_history.sms_id');
}
$this->db->order_by('vote', "DESC");
$c = $this->db->get();

and this the error i get :
A Database Error Occurred
Error Number: 1142
SELECT command denied to user 'db_name'@localhost for table 'id'
SELECT *, COUNT('like_today.sms_id') as vote FROM `sms` LEFT JOIN `sms`.`id` ON `sms`.`id` = `like_today`.`id` WHERE `sms`.`status` = 'A' GROUP BY `like_today`.`sms_id` ORDER BY `vote` DESC . Any help?

this=>
$this->db->join('id',
replace and put =>
$this->db->join('like_today',


RE: how to solve this db error? - SubjectX - 04-15-2016

Use of word "like" could be problematic, yes.


RE: how to solve this db error? - waptik - 04-15-2016

(04-14-2016, 03:40 PM)jonathanq Wrote:
(04-14-2016, 01:36 PM)waptik Wrote: I am trying to list statistics about my contents.
I have these tables{(sms:id,status,like,user,sms); (like_today:id,sms_id,vote,date); (like_history:id,sms_id,vote,date) }

This is my php code:

$this->db->select("*")->from("sms");
$this->db->where('sms.status', 'A');
if($day=='today'){
$this->db->select("COUNT('like_today.sms_id') as vote");
$this->db->join('id', 'sms.id = like_today.sms_id', 'LEFT');
$this->db->group_by('like_today.sms_id');
}else{
$this->db->select("COUNT('like_history.vote') as vote");
if($day=='yesterday')
$this->db->where('like_history.date', date('Ymd',strtotime('-1 day')));
if($day=='week')
$this->db->where('like_history.date >', date('Ymd',strtotime('-1 week')));
if($day=='month')
$this->db->where('like_history.date >', date('Ymd',strtotime('-1 month')));
$this->db->join('id', 'sms.id = like_history.sms_id', 'LEFT');
$this->db->group_by('like_history.sms_id');
}
$this->db->order_by('vote', "DESC");
$c = $this->db->get();

and this the error i get :
A Database Error Occurred
Error Number: 1142
SELECT command denied to user 'db_name'@localhost for table 'id'
SELECT *, COUNT('like_today.sms_id') as vote FROM `sms` LEFT JOIN `sms`.`id` ON `sms`.`id` = `like_today`.`id` WHERE `sms`.`status` = 'A' GROUP BY `like_today`.`sms_id` ORDER BY `vote` DESC . Any help?

this=>
$this->db->join('id',
replace and put =>
$this->db->join('like_today',

Thanks man,it works!