Jump to content

Archived

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

neddy

php mysql query question

Recommended Posts

i have a table setup with the following in

id
game_id
name

now i want to filter/search the table for specific results so i did this

[code]SELECT * FROM my_table WHERE name LIKE %$name% ORDER BY id DESC[/code]

thats all well and good, i can use anything as $name and it returns all the rows with $name in name..

now i want to filter them more so i try

[code]SELECT * FROM my_table WHERE game_id = '1' OR game_id = '2' AND name LIKE %$name% ORDER BY id DESC[/code]

it gives me results where name is nothing like $name ?

any idea where im going wrong? or is there a better way to do what im trying to do?

if i havnt explained what im trying to do very well then please say so and ill try to explain a bit better [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /]

cheers

EDIT: forgot to say if i just do [code]SELECT * FROM my_table WHERE game_id = '1' AND name LIKE %$name% ORDER BY id DESC[/code]

it works

but i want to be able to search for multiple game_ids...

Share this post


Link to post
Share on other sites
[code]
SELECT * FROM my_table WHERE game_id IN ('1','2','3') AND name LIKE %$name% ORDER BY id DESC
[/code]

Share this post


Link to post
Share on other sites
wow :D

working perfectly so far

thanks a bunch [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Share this post


Link to post
Share on other sites

×

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.