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
https://forums.phpfreaks.com/topic/273759-in-and-and-in-asingle-sql-query/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.