PHP display all values of an array to use in mysql_fetch_array function?
I'm having a bit of difficulty using the values in a PHP array for a mysql function.
I have an array,
$a[0] = 89
$a[1] = 23
$a[2] = 15
$a[3] = 28
$a[4] = ...
And I need to generate a st开发者_如何学Pythonring like so:
$result_array = 'ID = 89 OR ID = 23 OR ID = 15 OR ID = 28 OR ID = ...';
To fetch values from my DB:
$result_test = mysql_query("SELECT * FROM Events Where $result_array");
But I do not know how to create the string $result_array from the array $a.
$result_test = mysql_query("SELECT * FROM Events Where ID in (".implode(',' , $a).")");
Use the IN operator and send the list as 89,23,15,28
etc
So the query will become ID in (89,23,15,28)
$result_test = mysql_query("SELECT * FROM Events Where ID IN (".implode(',',$a).')');
精彩评论