Search This Blog

Saturday, May 22, 2010

Modifying MySQL Where Statement Based on Array

Programmer Question

Using an array like this:



$data = array
(
'host' => 1,
'country' => 'fr',
)


I would like to create a MySQL query that uses the values of the array to form its WHERE clause like:



SELECT *
FROM table
WHERE host = 1 and country = 'fr'


How can I generate this query string to use with MySQL?



Find the answer here

No comments:

Post a Comment

Related Posts with Thumbnails