harkly Posted November 13, 2008 Share Posted November 13, 2008 Checking to see if I am on a good path. I have a search form that has a drop down and then input. Based on the drop down I will search different tables. I am very new at coding and would like to see if my thought process is going in the right direction. Can someone tell me if I have chosen the most applicable IF statement and if I have the general idea? $field=$_GET["field"]; if ($field == "artist") echo "You have choosen to search for an Artist."; elseif ($field == "artwork") echo "Art work it is!"; elseif ($field == "keywords") echo "I will check all keywords."; else echo "I will check everything."; Obviously I'm not going to have the ECHO's but will have my search code. But going simple for now. ----- My search form <form name="search" method="get" action="artist.php" onsubmit="return checkform(this);"> Seach <select NAME="field"> <option value="all">All</option> <option value="artist">Artists</option> <option value="artwork">Art Works</option> <option value="keywords">Keywords</option> </Select> for <input type="text" name="find" /> <input type="hidden" name="search" value="yes" /> <input type="submit" name="search" value="search" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/132609-if-statment/ Share on other sites More sharing options...
Goldeneye Posted November 13, 2008 Share Posted November 13, 2008 Aside from validating form input (which I assume you're working on), your code seems to be good so far. Of course, of course you might want to add a 'Search All' option to the select menu and then use the 'else' statement to return an error along the lines of, "invalid option" Also, not that's absolutely necessary, but you could also use POST for this as it wouldn't be passed through the URL. Have you tried testing this code yet? Quote Link to comment https://forums.phpfreaks.com/topic/132609-if-statment/#findComment-689538 Share on other sites More sharing options...
.josh Posted November 13, 2008 Share Posted November 13, 2008 if the only thing that's going to change in your actual query is $field then there's no need to make all those if/elseif's just make one query with the var plugged into it. Quote Link to comment https://forums.phpfreaks.com/topic/132609-if-statment/#findComment-689541 Share on other sites More sharing options...
Barand Posted November 13, 2008 Share Posted November 13, 2008 OK so far, except you have 2 input elements with the same name "search" Quote Link to comment https://forums.phpfreaks.com/topic/132609-if-statment/#findComment-689543 Share on other sites More sharing options...
harkly Posted November 13, 2008 Author Share Posted November 13, 2008 I have it working and I used a javascript that has a stupid pop-up if 'find' is left empty. Using the javascript would I need another else statement to return an error, can I not just use another else statement to validate a blank 'find' ? I was thinking I would need all the if/else statements because the information lies in different tables and I didn't want to search one table for info that I know isn't there, also if looking for an artist their name can also be included in an art work and I want to be specific. Quote Link to comment https://forums.phpfreaks.com/topic/132609-if-statment/#findComment-689627 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.