Im trying to fill query with array. As I know I can display array with function foreach(); but im not able to put it in mysql query
Im trying to do something like this:
<?php
$arr = array("arr_1", "arr_2", "arr_3", "arr_4");
$query = mysql_query("SELECT * FROM users WHERE user = '1'".
foreach($arr as $arr) {
echo "AND user = '".$arr++."'";
}
." ORDER BY id";
?>
Script have to display this as:$query = mysql_query("SELECT * FROM users WHERE user = '1' AND user = 'arr_1' AND user = 'arr_2' AND user = 'arr_3' AND user = 'arr_4'");
But this doesnt work becouse you cant put foreach() in mysql_query();.
So what I need is script that do the same thing ( display array in query string )
Thanks.
mysql_*functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.userbe equal to both '1' and 'arr_1'? Perhaps you just need to useINhere, likeSELECT * FROM users WHERE user IN (1, 'arr_1', ...)?user IN ('arr_1','arr_2','arr_3')BTW this does OR