Current location: Hot Scripts Forums » Programming Languages » PHP » SQL Filters


SQL Filters

Reply
  #1 (permalink)  
Old 06-30-05, 04:44 AM
phppick phppick is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
SQL Filters

HI,

I am doing some Dynamic Reporting. For sample lets say, in the Filter Window (Parameter Passing Window), I have,

1.Branch (All, B1, B2, B3, B4)
2.Applicant Type (i.e All, Bachelor, Masters)
3.Gender (All, Male,Female)
4.Religion (All, Christian, , , )
5.Country (All, ....)
6.Marital Status(All, Married, Single, Divorced)

User have many options to choose, before he/she click 'Search' to View Results.
Example 1: Select (Branch) B1, Male, Single (M.Status), All (Country)
Example 2: Select (Branch) All, Female, All (M.Status), UK (Country)

How to Write a sample & Compact Query for this type.. insted of writing so many queries..

Any Ideas.

Thanks
Jen
Reply With Quote
  #2 (permalink)  
Old 06-30-05, 01:11 PM
dennispopel dennispopel is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 263
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

I don't know why do you thinks this is difficult: just use several select boxes in the form and then just build single query like:

$sql = "SELECT * FROM tableName WHERE 1=1 " .
(($x = $_GET['branch']) ? " AND branch='$x'" : "") .
(($x = $_GET['type']) ? " AND type='$x'" : "") .
(($x = $_GET['gender']) ? " AND gender='$x'" : "")

and so on.
__________________
onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
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
form handling to build SQL code ski_woman PHP 1 11-24-04 02:58 PM
1 3 5 4, SQL SELECT, each # another SQL eq1987 PHP 4 07-05-04 07:03 PM
Help with ASP & FORMS blessedrub ASP 0 01-23-04 10:22 AM
ASP Calendar..HELP...pls jimthepict ASP 1 07-31-03 05:01 PM
change my field in this example sal21 ASP 3 07-14-03 02:49 AM


All times are GMT -5. The time now is 06:53 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.