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.