Current location: Hot Scripts Forums » Programming Languages » PHP » Nested Query in PHP/MYSQL

Nested Query in PHP/MYSQL

Reply
  #1 (permalink)  
Old 07-27-04, 01:28 AM
truesilentassassin truesilentassassin is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Nested Query in PHP/MYSQL

Hello,

I have several categories I am quering from, one of the options (stored as a category in my category table) is All Categories.

I am now able to query for a particular query. The category is selected by the user and I use $_GET to query. This is working fine.

What I would like to do is, when a user selects All Categories from the category option, the query should leave the cagtegory clause in the query and return all results.

How do I do nested queries in PHP?

Here is how my code for query looks now:

$query2 = "SELECT ccode, category_name, phone, address, city, state, category from category_details, category, city, state where state.id = category_details.fk_state and city.id = category_details.fk_city and category.id = category_details.fk_category and category = '{$_GET['category']}' and city = '{$_GET['city']}'";

I would like to have a nested query which first checks (using $_GET) to see if "All Categories" is clicked by the user, if it is clicked then have a query similar to the above just loosing the category part, if other category is clicked, use the above query.

Please help me with this nested query.

Appreciate your help.

Thanks in advance.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-27-04, 03:38 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
try:
PHP Code:
$query2 "SELECT ccode, category_name, phone, address, city, state, category from category_details, category, city, state where state.id = category_details.fk_state and city.id = category_details.fk_city and category.id = category_details.fk_categoryand and city = '{$_GET['city']}'";
isset(
$_GET['category']) ? $query2 .= "and category = '{$_GET['category']}'"
hope it helps
Wille
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-27-04, 07:50 PM
truesilentassassin truesilentassassin is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
I'll try that

Thanks for your reply!

I'll try that
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share 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
PHP/MYSQL Table and query HELP!! truesilentassassin PHP 3 07-25-04 06:42 AM
HTML tables from PHP/MySQL query MikeNL PHP 3 01-24-04 02:47 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 01:57 AM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.