1

This is my query:

$query = $db
    ->select()
    ->from(array('ns' => 'news_subscriber'),
        array('ns.id', 'ns.subscriber_email')
    )
    ->where('ns.id NOT IN (?)', 
        $db
            ->select()
            ->from(array('nss' => 'news_subscribers_has_news_letter_content'),
                array('nss.news_subscribers_id')
            )
            ->where('nss.news_letter_content_id =' , $id)
    );
$subscribers = $db->fetchAll($query);

I am getting this error:

Syntax error or access violation 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 '))))' at line 1`

I feel the problem is in the "IN".

Any ideas?

1
  • I have fixed your formatting in this post for you this time, but please review stackoverflow.com/editing-help when posting questions in future. Commented Apr 28, 2011 at 8:38

5 Answers 5

4

Your query has multiple errors.

  • ->where('nss.news_letter_content_id =', $id)

    You forgot the ? after the =.

  • ->where('ns.id NOT IN (?)', $db->select() ...

    I'm pretty sure that you have to convert the subquery object to an array first.

Sign up to request clarification or add additional context in comments.

Comments

2
$subscribers = $db->fetchAll($db->select()->from('news_subscriber ns, subscriber_email se')
->where('ns.id NOT IN ('.$db->select()->from( 'news_subscribers_has_news_letter_content nss') ->where('nss.news_letter_content_id =',$id))));

I dont use array in my select. See if this is helpful.

Comments

1

you may write your query like this..please check below.

$subscribers = $db->fetchAll($db->select()->from(array('ns' => 'news_subscriber','nss'=> 'news_subscribers_has_news_letter_content'),
                                array('ns.id',
                                    'ns.subscriber_email','nss.news_subscribers_id'))                
                ->where('ns.id NOT IN (?) AND 'nss.news_letter_content_id =',$id);

Thanks.

Comments

1

Note that you can always see the whole query to see where is the problem.

echo (string)$query;
// die();

Comments

0

are you sure that all the variables that you have used in your query are getting a value, most of the times this error occurs if the values of the variables in the query are uninitialized or "" in case of a string ......... Also in this case I think you have an extra ')' in the end hope that helps

1 Comment

yeap i just checked them one by one

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.