pure_skill_2000 Posted April 19, 2008 Share Posted April 19, 2008 Hi Im having a dumb problem with the code for a search, I want to allow the user to search with different fields, with the options populated from the choices in the database. For example LFA 3 in 2004 but I cannt get it to work Ive never tried this before its probably simple but im lost! <?php //// filename = search.php <form name="search" method="post" action="result.php"> <select name="metode" size="1"> <option value="Aircraft Type">Aircraft Type</option> <option value="LFA">LFA</option> </select> <input type="text" name="search" size="25"> <input type="submit" value="Begin Searching!!"> </form> ?> //// filename = result.php <?php $hostname = $username = $password = $usertable = $dbName = MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); @mysql_select_db( "$dbName") or die( "Unable to select database"); ?> <? //error message (not found message) $XX = "No Record Found"; $query = mysql_query("SELECT * FROM $usertable WHERE $metode LIKE '%$search%' LIMIT 0, 30 "); while ($row = mysql_fetch_array($query)) { $variable1=$row["Aircraft Type"]; $variable2=$row["LFA"]; $variable3=$row["Intensity"]; print ("this is for $variable1, and this print the variable2 end so on..."); } //below this is the function for no record!! if (!$variable1) { print ("$XX"); } //end ?> Ive tried to follow an online tutorial Quote Link to comment Share on other sites More sharing options...
unidox Posted April 19, 2008 Share Posted April 19, 2008 Try this: http://www.avengex.com/tutorials/97/Simple_Searching/ and google for more if needed. Quote Link to comment Share on other sites More sharing options...
pure_skill_2000 Posted April 19, 2008 Author Share Posted April 19, 2008 Thanks ive done simple searches like that and gotten them to work fine, I want the choices they can select to search from to populate from the database though, like drop downs Quote Link to comment Share on other sites More sharing options...
Barand Posted April 19, 2008 Share Posted April 19, 2008 Could be an old tutorial try $metode = $_POST['metode']; $search = $_POST['search']; $query = mysql_query("SELECT * FROM $usertable WHERE $metode LIKE '%$search%' LIMIT 0, 30 "); Quote Link to comment Share on other sites More sharing options...
pure_skill_2000 Posted April 19, 2008 Author Share Posted April 19, 2008 I have a syntax "<" error on line 3 any suggestions? <?php //// filename = search.php <form name="search" method="post" action="result.php"> <select name="metode" size="1"> <option value="Aircraft Type">Aircraft Type</option> <option value="LFA">LFA</option> </select> <input type="text" name="search" size="25"> <input type="submit" value="Begin Searching!!"> </form> ?> Quote Link to comment Share on other sites More sharing options...
unidox Posted April 20, 2008 Share Posted April 20, 2008 Yea, remove the php brackets. Unless you want to echo the whole thing. Quote Link to comment Share on other sites More sharing options...
pure_skill_2000 Posted April 20, 2008 Author Share Posted April 20, 2008 I got this sorted did it a totally diff way in the end Quote Link to comment Share on other sites More sharing options...
monkeypaw201 Posted April 20, 2008 Share Posted April 20, 2008 would you mind posting it so other people with the same question can see? Quote Link to comment 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.