creating a search form with multiple options, like the search form used on this site?

Reply

Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

creating a search form with multiple options, like the search form used on this site?

 
0
  #1
Aug 10th, 2008
I've been able to put together a basic search form that allows users to search my database by entering their last name. My question is how do I offer them an option, using a radio button, to allow them to search by, for example, a city or state or age, etc. Here is the code I have in place for a search of a user's last name:

<?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){

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

If I used a radio button, this code would represent my "last name" search, but how would I also allow the user to search via other options? I'm assuming I would use IF...Else, but don't know how to construct the code around this search code.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 213
Reputation: nikesh.yadav is an unknown quantity at this point 
Solved Threads: 17
nikesh.yadav's Avatar
nikesh.yadav nikesh.yadav is offline Offline
Posting Whiz in Training

Re: creating a search form with multiple options, like the search form used on this site?

 
0
  #2
Aug 11th, 2008
only a litle change i m using switch u can use 'if '

  1. <?php
  2.  
  3. $SQL_FROM = 'adr';
  4. switdh($_request['radiobuttomname']){
  5. case 'lastname':
  6. $SQL_WHERE = 'last';
  7. case 'city:
  8. $SQL_WHERE = 'city';
  9. and
  10. so on ....
  11.  
  12. ?>
  13. <?php
  14. $searchq = strip_tags($_GET['q']);
  15. $getRecord_sql = 'SELECT * FROM '.$SQL_FROM.' WHERE '.$SQL_WHERE.' LIKE "'.$searchq.'%"';
  16. $getRecord = mysql_query($getRecord_sql);
  17. if(strlen($searchq)>0){
  18.  
  19. echo '<ul>';
  20. while ($list = mysql_fetch_array($getRecord)) {?>
  21. <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>
  22. <?php }
  23. echo '</ul>';
  24. ?>
  25. <?php } ?>
  26.  
Help as an alias

I think programming is great................
Tour Travel weblink by me and about Tour ,
Go To My Home Page and I m in Webdevelopment.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

Re: creating a search form with multiple options, like the search form used on this site?

 
0
  #3
Aug 13th, 2008
I'm not sure how the if/else or switch statement would work if I'm attempting to use it with a radio button. The idea is to give the user an option between searching via a 'last name' or searching using 'city'. The name of the radio buttons are 'last' and 'city'. Would it be better to use switch or if, and what is the difference? Thanks

<?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 } ?>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC