Xtremer360 Posted September 13, 2012 Share Posted September 13, 2012 I'm getting a syntax error on this line because of the CONCAT function and I'm trying to figure out where the ending ) needs to be because I think that's the issue here. $this->db->select("CONCAT_WS(' ', ".$this->master_model->users_table.".first_name", $this->master_model->users_table.".last_name) AS author", FALSE); Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 13, 2012 Share Posted September 13, 2012 The problem is probably the placement of your comma. However you really should know by now and I've seen you be told: Post the exact entire error, and post the section of code not just one line, since errors can be from the previous line. Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted September 13, 2012 Author Share Posted September 13, 2012 Yes I'm sorry. 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 'FROM (`news_articles`) JOIN `users` ON `users`.`user_id` =`news_articles`.`news_' at line 2 SELECT `news_articles`.`news_article_id`, `news_articles`.`news_article_title`, DATE_FORMAT(news_articles.news_article_posting_date, '%M %D, %Y') AS news_article_posting_date, CONCAT_WS(' ', `users`.`first_name`, `news_article_categories`.`news_article_category_name` FROM (`news_articles`) JOIN `users` ON `users`.`user_id` =`news_articles`.`news_article_author_id` JOIN `news_article_categories` ON `news_article_categories`.`news_article_category_id` =`news_articles`.`news_article_category_id` Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 13, 2012 Share Posted September 13, 2012 Like I said, the problem is the comma. Look at the generated SQL. It's missing the last_name as author part. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted September 13, 2012 Share Posted September 13, 2012 There is no a separator specified in the first argument. Ops, there is empty string, sorry about that. Where do you close CONCAT_WS ? Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted September 13, 2012 Author Share Posted September 13, 2012 I have a comma in there though. Is it just on the wrong side of the "? Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 13, 2012 Share Posted September 13, 2012 What do YOU THINK? Did you TRY changing it yet? Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted September 13, 2012 Author Share Posted September 13, 2012 Yes and still got the same syntax error. Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 13, 2012 Share Posted September 13, 2012 I very very highly doubt it. Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted September 13, 2012 Author Share Posted September 13, 2012 $this->db->select("CONCAT_WS(' ', ".$this->master_model->users_table.".first_name,", $this->master_model->users_table.".last_name) AS author", FALSE); Didn't work. Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 13, 2012 Share Posted September 13, 2012 *headdesk* You still have a comma where there shouldn't be one. What do you *think* the code you've posted does. Why are you sending 3 arguments to that function? Why doesn't the last_name as author part show up in your final query? Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted September 13, 2012 Share Posted September 13, 2012 Where is the last parenthesis of this: SELECT `news_articles`.`news_article_id`, `news_articles`.`news_article_title`, DATE_FORMAT(news_articles.news_article_posting_date, '%M %D, %Y') AS news_article_posting_date, CONCAT_WS(' ', `users`.`first_name`, `news_article_categories`.`news_article_category_name` FROM (`news_articles`) JOIN `users` ON `users`.`user_id` =`news_articles`.`news_article_author_id` JOIN `news_article_categories` ON `news_article_categories`.`news_article_category_id` =`news_articles`.`news_article_category_id` Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted September 13, 2012 Author Share Posted September 13, 2012 $this->db->select("CONCAT_WS(' ', ".$this->master_model->users_table.".first_name", $this->master_model->users_table.".last_name) AS author)"); Doesn't work either. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted September 13, 2012 Share Posted September 13, 2012 Could you echo it ? Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted September 13, 2012 Author Share Posted September 13, 2012 Echo what? Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted September 13, 2012 Share Posted September 13, 2012 Echo what? $this->db->select("CONCAT_WS(' ', ".$this->master_model->users_table.".first_name", $this->master_model->users_table.".last_name) AS author)"); Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted September 13, 2012 Author Share Posted September 13, 2012 It wont' because there's an error in there. Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 13, 2012 Share Posted September 13, 2012 YOU STILL HAVE A COMMA WHERE THERE SHOULDN'T BE ONE. No wonder you don't get any help here. You refuse to actually learn. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted September 13, 2012 Share Posted September 13, 2012 It wont' because there's an error in there. I know, just echo before to send it. We want to see only the string Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted September 13, 2012 Author Share Posted September 13, 2012 $this->db->select("CONCAT_WS(' ', ".$this->master_model->users_table.".first_name" $this->master_model->users_table.".last_name) AS author", FALSE); I'm sorry if I'm being a problem but I honestly don't see the issue. I removed the comma that I think it is. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 13, 2012 Share Posted September 13, 2012 I think it would help if you posted all the lines of code that are building this query (i.e. the final query you posted doesn't match the fragment you have been posting.) Edit: For the fragment you have been posting - $this->db->select("CONCAT_WS(' ',{$this->master_model->users_table}.first_name, {$this->master_model->users_table}.last_name) AS author", FALSE); Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted September 13, 2012 Author Share Posted September 13, 2012 $this->db->select($this->master_model->news_articles_table.'.news_article_id'); $this->db->select($this->master_model->news_articles_table.'.news_article_title'); $this->db->select("DATE_FORMAT(".$this->master_model->news_articles_table.".news_article_posting_date, '%M %D, %Y') AS news_article_posting_date", FALSE); $this->db->select("CONCAT_WS(' ', ".$this->master_model->users_table.".first_name" $this->master_model->users_table.".last_name) AS author", FALSE); $this->db->select($this->master_model->news_article_categories_table.'.news_article_category_name'); $this->db->from($this->master_model->news_articles_table); $this->db->join($this->master_model->users_table, $this->master_model->users_table.'.user_id ='.$this->master_model->news_articles_table.'.news_article_author_id'); $this->db->join($this->master_model->news_article_categories_table, $this->master_model->news_article_categories_table.'.news_article_category_id ='.$this->master_model->news_articles_table.'.news_article_category_id'); $query = $this->db->get(); return $query->result(); Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 13, 2012 Share Posted September 13, 2012 Also, I edited my post above with some syntax that should work that eliminates all the concatenation that is error prone because it is difficult to see where the php syntax starts and ends where the sql syntax starts and ends (you are missing a comma that is part of the CONCAT_WS() sql syntax and missing some dots that are part of the php concatenation syntax.) It's best to have as few syntax breaks/switches as possible. Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted September 13, 2012 Author Share Posted September 13, 2012 Is there anyway of doing that line without having the {}? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 13, 2012 Share Posted September 13, 2012 Why are the {object_property} a problem? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.