PDA

View Full Version : mysql_query() question



tanel96
February 23rd, 2008, 09:02 AM
I have an array called rightStuff that houses a bunch of numbers, like so:


$rightStuff = ("1","3","5");

Now, i'm trying to write a mysql query that would only picks out rows, where its 'engine' field value is found in the array...



mysql_query("SELECT * FROM table WHERE engine = ... ");



How should I achieve something like that ?

chrisclick
February 23rd, 2008, 10:59 AM
if Im correct (im not too sure)

this might work



mysql_query("SELECT * FROM table WHERE engine = '$rightStuff'");

prstudio
February 23rd, 2008, 02:00 PM
depending on how large and dynamic the rightstuff array is - you could just reference each point within the array like

rightstuff[0]

so like

SELECT * FROM table WHERE engine = '$rightstuff[0]' AND WHERE engine = '$rightstuff[1]' and so on...

but if it will be dynamic - then you will have to loop through the array grabbing the query result and adding it to itself.

that should be a good start :)