I am trying to build an SQL search from input field "postcode" with multiple zipcode.
My input field is working like that: user add different zipcode (french),
the value of the input (name = postcode) is: value="35200, 53333, 23400"
the URL (post) after submit is: &postcode=35200%2C53333%2C23400
Now the query PHP part (working with only one postcode added):
$postcode = (!empty($array['postcode']) && !is_array($array['postcode']) AND $array['postcode'] != $language['value_postcode']) ? $bdd->quote($array['postcode']) : 0;
$condition .= (!empty($postcode)) ? " AND s.postcode = $postcode" : "";
This is working with ONLY ONE ZIPCODE …
If I add an other zip code, the request is not working.
What to do to change the request working with multiple zipcode?
2
Answers
I assume you have already fetched the multiselect input as
So now, you only need to convert the string value $postcode into array as
This way all your multiple values are accessible in $postcode_arr array for next requirement.
Reference link:
https://www.php.net/manual/en/function.explode.php
Otherwise, you have not added the question properly. So, I suggest you to add full code having database query generated from your form/data collector.
Then only, one can debug for any logical issue there may exist and depending that we can help you fix the issue.
As you are already having comma separated values
value="35200, 53333, 23400"
you can directly give a try with IN operator