| | |
creating a search form with multiple options, like the search form used on this site?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2008
Posts: 129
Reputation:
Solved Threads: 0
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:
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.
<?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.
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 '
PHP Syntax (Toggle Plain Text)
<?php $SQL_FROM = 'adr'; switdh($_request['radiobuttomname']){ case 'lastname': $SQL_WHERE = 'last'; case 'city: $SQL_WHERE = 'city'; and so on .... ?> <?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 } ?>
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.
I think programming is great................
Tour Travel weblink by me and about Tour ,
Go To My Home Page and I m in Webdevelopment.
•
•
Join Date: Mar 2008
Posts: 129
Reputation:
Solved Threads: 0
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 } ?>![]() |
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP)
Other Threads in the PHP Forum
- Previous Thread: PHP and Shell Commands
- Next Thread: show club presidents info hide everyone else's
| Thread Tools | Search this Thread |
action address advanced ajax apache api array auto autoincrement basics beginner broken cakephp class cms code codingproblem combobox cron curl database date datepart display domain dynamic email error errorlog file folder form format forms function functions google head href htaccess html image include includingmysecondfileinthechain interactive ip javascript job joomla js limit link load login malfunctioning masterthesis menu multiple mysql nodes oop outofmemmory paging password paypal pdf php popup problem procedure query ram random reference script search server sessions smarty source space sql stored syntax system table traffic tutorial unicode unset up-to-date upload url validation variable video web webapplications websitecontactform youtube





