blueman378 Posted December 5, 2007 Share Posted December 5, 2007 hi guys im trying to build a game search engine so i need a script which is something like mysql_query("SELECT * FROM games ORDER BY gName WHERE gName='$search1' OR gName='$search2' OR gname='$search3'"); thanks Quote Link to comment Share on other sites More sharing options...
metrostars Posted December 5, 2007 Share Posted December 5, 2007 I don't exactly see what you want. That should work fine although it's usually better to put the where first. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted December 5, 2007 Share Posted December 5, 2007 From where i get ur idea, i think u try switch statement. switch the case on every search keyword. Quote Link to comment Share on other sites More sharing options...
blueman378 Posted December 5, 2007 Author Share Posted December 5, 2007 hmm my bad, i guess i should have checked first, its cause i had no idea that there was a OR in mysql, so i kinda put that together as i example, but it should work? haha cool, well i guess ill use this thread to ask my second question, i have a search form which is a simple form, <form name="search"> <input type="text" name="searchf"> <input type="submit" value="Search!"> </form> what im looking for is a script which splits the words based on the space, it thencounts how many words there are and assigns them each a variable name "$search1" "$search2" ect, i then need a small script which will check to see how many variables there are and will do what is listed above, adding as many ors as needed. and one small modification to what i wanted before i actually wanted AND not OR, or if possible a AND/OR it searches based on priority, so the results which match the AND come above the OR im assuming you would use explode on the " " character or something like that? thanks Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 5, 2007 Share Posted December 5, 2007 here you go just a rough sketch of things <?php if (isset($_POST['submitform'])) { $strWords = $_POST['searchf']; $strType = $_POST['type']; $arrWords = explode(" ",$strWords); $arrMatches = array(); foreach ($arrWords as $strKey => $strValue) { array_push($arrMatches," gName='$strValue' "); } $strSql = "SELECT * FROM games WHERE ".implode(" $strType ",$arrMatches) ." ORDER BY gName"; print $strSql; } ?> <form name="search" method="post"> <input type="text" name="searchf"> <select name="type"> <option value="AND">AND</option> <option value="OR">OR</option> </select> <input type="submit" name="submitform" value="Search!"> </form> Quote Link to comment Share on other sites More sharing options...
blueman378 Posted December 6, 2007 Author Share Posted December 6, 2007 ah thanksmate thats brilliant. cheers 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.