I've tried to post on a few other forums for information on how to write a very simple search script that will allow multiple search options to search a mysql database. I have a script written that searches by a users last name, but I want to also offer the option to search by a users city or state. I have a couple radio buttons in the html, but don't have any idea how to manipulate the php. Any suggestions? Here's the code I have:

<?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 } ?>

The bottom portion is an AJAX response that makes an auto suggestion according to what letters you type. Thanks in advance!

    You will need to change the javascript that calls this php page in addition to the php page. (look like Scriptaculous Autocompleter to me.)

    When you figure out how to send an extra url key/value pair with your javascript function, you could use a switch statement to decide how to search:

    switch ($_GET['radioSearch']) {
    		case "last":
    			$SQL_WHERE = 'last';
    			break;
    		case "city":
    			$SQL_WHERE = 'city';
    			break;
    		case "state":
    			$SQL_WHERE = 'state';
    			break;
    	}
      Write a Reply...