Current location: Hot Scripts Forums » Programming Languages » PHP » searching from a form where some fields are not required


searching from a form where some fields are not required

Reply
  #1 (permalink)  
Old 12-07-03, 10:49 PM
bobdole bobdole is offline
New Member
 
Join Date: Dec 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
searching from a form where some fields are not required

Ok, I have a form with things like last name, first name, phone number, etc.

I need for my php script to search through my mysql database, but only if the user entered something into the given field. So if they only entered a first name it would only find the entries in the database with that first name. None of the fields are required.

How can I either search for all the entries with a first name, and then search those results for all the entries with the specified last name and so on, or just do one search where i check before hand to see if there are entries in each field and if there are not, simply put a wildcard in that field in the query.

Basically I would like to "build" the query as I check each field to see if anything is there. Any Ideas?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-08-03, 05:14 AM
zero's Avatar
zero zero is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
I do'nt write english good.i post code the same proplem you
use:mysql,
table tt(id int primary key firstname char,lastname char,....,)
<?PHP
$str="select * from tt ";$check=mysql_length($str);
if($_post(firstname)<>"") {
mysql_length($str)=$check;
$str=$str."where (firstname=$_post(firstname))";
}
else $str=$str."and (firstname=$_post(firstname))" ;
if($_post(lastname)<>"") {
mysql_length($str)=$check;
$str=$str."where (lastname=$_post(lastname))";
}
else $str=$str."and (lastname=$_post(lastname))" ;

?>
the same for filed #
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
lock form fields using checkbox jonathen JavaScript 5 02-04-05 04:35 PM
Formmail Script Fix - Cant display multiple list selections.. zamen PHP 3 05-02-04 10:59 AM
hidden fields not passsing values! aleksgurl Perl 1 11-07-03 01:20 AM
SQL database registration form help vinhkhuong PHP 3 10-10-03 04:49 AM
passing array to hidden fields in form on next page? seala ASP 2 09-04-03 03:40 PM


All times are GMT -5. The time now is 01:26 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.