Jump to content

Allowing Multiple Search Options While Using AJAX feature?


Recommended Posts

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! 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.