Jump to content

IN and AND in asingle sql query?


wright67uk

Recommended Posts

I'm trying to write a query where:

 

I pull records for any user_id that's within $mystring, whilst linking the registration table and 18scorecard table by user_id.

Im not sure the best way to do this.

 

$mystring gets its value from an implode at the moment its 5,6,7

 

Heres what ive got so far...

 

("SELECT * FROM registration, 18scorecard WHERE registration.user_id IN ($mystring) AND 18scorecard.user_id = registration.user_id");

 

Is it possible to change this query, to get the result i'm looking for?

 

At the moment im greeted with a mysql fetch array error

Link to comment
Share on other sites

Yes your right. :-\ ...

 

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 ') AND 18scorecard.user_id = registration.user_id' at line 1

 

After using this, i realised that $mystring didn't echo as it should. I have now ensured that the variable carries a value, and now everything works fine. I will also ensure that I use error messages and version numbers if I ever need help again. Thankyou

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.