b Posted August 13, 2008 Share Posted August 13, 2008 Hi, I have a code that allows for a search in my database of last names, but I would like to offer the user an option to also search for information according to other options, like city or state. The code I have now uses some javascript that automatically suggests possibilities as you type. I can obviously change the code to search for city or state, but how do I offer both options? I'm envisioning a form that has a simple search form with two radio buttons to indicate a search via last name or city. I think this is fairly simple task, but I'm so new to php that I'm utterly lost as to how to do it. Here is the code I have, and any help would be greatly appreciated: <?php include('config.php'); $SQL_FROM = 'adr'; $SQL_WHERE = 'last'; ?> <?php $searchq = strip_tags($_GET['q']); $getRecord_sql = 'SELECT * FROM '.$SQL_FROM.' WHERE '.$SQL_WHERE.' LIKE "'.$searchq.'%"'; $getRecord = mysql_query($getRecord_sql); if(strlen($searchq)>0){ // ---------------------------------------------------------------- // // AJAX Response // ---------------------------------------------------------------- // echo '<ul>'; while ($list = mysql_fetch_array($getRecord)) {?> <li><a href="runners2.php?name=<?php echo urlencode($list['first'].' '.$list['last']); ?>"><?php echo $list['last']; ?> <small><?php echo $list['first']; ?></small><small><?php echo $list['city']; ?></small><small><?php echo $list['age']; ?></small></a></li> <?php } echo '</ul>'; ?> <?php } ?> I assume I would need two AJAX responses, one for last name (which is what I have now) and one for city. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/119563-allowing-multiple-search-options-while-using-ajax-feature/ Share on other sites More sharing options...
ignace Posted August 13, 2008 Share Posted August 13, 2008 nope just use checkboxes, the user selects the criteria and then starts typing in the search field, the suggestions are then based on the criteria the user chose Quote Link to comment https://forums.phpfreaks.com/topic/119563-allowing-multiple-search-options-while-using-ajax-feature/#findComment-615974 Share on other sites More sharing options...
b Posted August 14, 2008 Author Share Posted August 14, 2008 I'm using radio buttons. But I can't figure out how to write the code. The radio buttons names are "last" for last name, and "city" for city. Would I use an If...Else statement, and if so, how do I write that into the code I have above. Any help is very much appreciated. I'm new to all this. Quote Link to comment https://forums.phpfreaks.com/topic/119563-allowing-multiple-search-options-while-using-ajax-feature/#findComment-616100 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.