Current location: Hot Scripts Forums » Programming Languages » PHP » Combining select statements


Combining select statements

Reply
  #1 (permalink)  
Old 08-12-05, 01:25 PM
jack_mcs jack_mcs is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Combining select statements

I need to combine a number of mysql select statements in php code. I have tried the UNION but I keep getting a syntax error.

The statemetns by themselves appear as:

$listing_englis_sql = "select " . $select_column_list . " l.sole_id, ld.language_id from " . TABLE_SOLE_DESCRIPTION . " ld, " . TABLE_SOLE . " l, " . TABLE_SOLE_TO_LINK_CATEGORIES . " l2lc where l.sole_status = '2' and l.sole_id = l2lc.sole_id and ld.sole_id = l2lc.sole_id and ld.language_id = '1' and l2lc.sole_categories_id = '" . (int)$current_category_id . "'";

$listing_french_sql = "select " . $select_column_list . " l.sole_id, ld.language_id from " . TABLE_SOLE_DESCRIPTION . " ld, " . TABLE_SOLE . " l, " . TABLE_SOLE_TO_LINK_CATEGORIES . " l2lc where l.sole_status = '2' and l.sole_id = l2lc.sole_id and ld.sole_id = l2lc.sole_id and ld.language_id = '2' and l2lc.sole_categories_id = '" . (int)$current_category_id . "'";

And my attempt at combining them appears as:

$listing_sql = ("select " . $select_column_list . " l.sole_id, ld.language_id from " . TABLE_SOLE_DESCRIPTION . " ld, " . TABLE_SOLE . " l, " . TABLE_SOLE_TO_LINK_CATEGORIES . " l2lc where l.sole_status = '2' and l.sole_id = l2lc.sole_id and ld.sole_id = l2lc.sole_id and ld.language_id = '1' and l2lc.sole_categories_id = '" . (int)$current_category_id . "')
UNION
(select " . $select_column_list . " l.sole_id, ld.language_id from " . TABLE_SOLE_DESCRIPTION . " ld, " . TABLE_SOLE . " l, " . TABLE_SOLE_TO_LINK_CATEGORIES . " l2lc where l.sole_status = '2' and l.sole_id = l2lc.sole_id and ld.sole_id = l2lc.sole_id and ld.language_id = '2' and l2lc.sole_categories_id = '" . (int)$current_category_id . "')";

I'm doing this since the various languages may not be enabled. So I thought to check each language and combine the sstatements that apply. I could do it with a bunch of if's but there are a minimum of four languages so that starts to get out of control.

If anyone can see how to get the above to work or if you can see a better way, I would appreciate the help.
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
select combobox value? lordy PHP 3 05-24-05 10:47 PM
Multiple Select phppick JavaScript 3 04-11-05 12:09 AM
Select List insert into DB The Omega JavaScript 1 01-12-05 12:51 PM
Select statements rocky PHP 3 08-03-04 07:08 AM
i have 3 select box this is urgent traceMe JavaScript 0 12-02-03 01:24 AM


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