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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/ 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377633 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377636 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377637 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377639 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377640 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377642 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377643 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377644 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377646 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377647 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377649 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377651 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377655 Share on other sites More sharing options...
Xtremer360 Posted September 13, 2012 Author Share Posted September 13, 2012 Echo what? Quote Link to comment https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377656 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377657 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377659 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377666 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377669 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377670 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377677 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377680 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377694 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377696 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 https://forums.phpfreaks.com/topic/268334-syntax-error-of-in-the-worng-place/#findComment-1377697 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.