samedi 23 juillet 2016

PHP - Only run a search if a dropdown value is chosen

I have a search on a site which I only want to display any results if something has been entered into one of the fields. I'm not really a php person so the best I could do was by adding this before the search:

<?php code on how to get the listings ... 

if ($search_location != "" || $search_keywords != ""  ) {

... code on how to display the listings.} ?>

As far as I understand this will only display the results if either the location or keywords are not empty. Works well so far.

My problem: there is also a dropdown to select a category ... I tried adding this like:

if ($search_location != "" || $search_keywords != "" || $search_categories != ""  ) {

But the search doesn't work if you only choose a category you have to enter in one of the other fields also, so I am assuming this was wrong.

Any help would be appreciated. Liz.

Aucun commentaire:

Enregistrer un commentaire