I got help from this post but need help on one more thing :) I have twelve drop downs with the option to select more than one value. On submit, these values are posted to another page where I do a mysql query to a database. If I select one value from each dropdown, it works. However, if I select more than one, only one is queried.
Here's the query output if I select multiple values:
SELECT *
FROM dummy_table
WHERE Role = 'Student'
OR Name = '**George,Sheila**'
OR City = 'New York';
I'd like it to be Name='George OR Sheila'
so I can pull people with both those names, or other values.
<?php
foreach($_POST as $key=>$option){
$countValue = count($option);
for($i=0; $i<$countValue; $i++){
$queryString_start_with_comma .= ",$option[$i]";
if($i >1){
$queryString_start_with_comma .= ",$option[$i] OR";
}
}
$queryString_remove_extra_comma= preg_replace("/,/", "", $queryString_start_with_comma, 1);
$query_string_with_and .= " OR $key = '$queryString_remove_extra_comma'";
unset($queryString_start_with_comma);
}
if ($sql_post_parameters == "AND") {
$query_string_second_part_ready = preg_replace("/AND/", "", $query_string_with_and, 1);
}
else {
$query_string_second_part_ready = preg_replace("/OR/", "", $query_string_with_and, 1);
}
$query_string= "SELECT * FROM dummy_table WHERE $query_string_second_part_ready";
TL;DR: I want to separate values pulled from a dropdown's POST with "OR" so I can query both in the database.
Thank you! :)