3

I need to archive something like this:

$array['0']="ID='1'";
$array['1']="ID='2'";

mysql_query("SELECT * FROM users WHERE {$array}");

This is a special condition and this is just an example; I'm not worried about security here as no value is passed by end user. Array values are auto generated and can be any size so I can't pass them manually.

1

1 Answer 1

2

only store the values in the array.

$array = ('aaa', 'bbb', 'ccc');

mysql_query("SELECT * FROM users WHERE ID IN ('".implode("','", $array)."')");

That will stick the array together and output somethin like:

mysql_query("SELECT * FROM users WHERE ID IN('aaa','bbb','ccc')");

you could leave out the ' if you only use Integers. But anything related to strings needs them in the SQL-statement, thus better use them from the getgo.

If you check for other things, you shoudl sticks thos with and AND or OR depending on how you want to check them and probably put them in different arrays

mysql_query("SELECT * FROM users WHERE ID IN ('".implode("','", $array_1 )."') OR name IN ('".implode("','", $array_2 )."')");
Sign up to request clarification or add additional context in comments.

Comments

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.