I built an array of strings and I'm attempting to query mySQL table. I want to find all rows that match my list of items separated with the word 'AND'. I've tried the code below but got no result back. How can I improve my code to perform the proper query using implode?
Thanks for any help.
$conditions = array(
'Monday',
'Tuesday',
'Wednesday'
);
$connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
if (mysqli_connect_errno())
{
die("Database connection failed: " . mysqli_connect_error() . " (" . mysqli_connect_errno() . ")");
}
$query = "SELECT * FROM match_tracker ";
// append the conditions
$query.= "WHERE " . implode(" AND ", $conditions);
$result = mysqli_query($connection, $query);
if ($result)
{
echo "Results positive. ";
}
if (!$result)
{
echo "Empty results.";
die("database query failed.");
"SELECT * FROM match_tracker WHERE Monday AND Tuesday AND Wednesday". Is that your intended sql string? If you wish to have something more meaningful, you'd have to go by way of associative arrays.IN()implode()in order for the query to work.INcreates anOR@Dagon