Forum Moderators: coopster

Message Too Old, No Replies

mysql union

         

webnoob

7:07 pm on Jun 1, 2005 (gmt 0)

10+ Year Member



i have a three table union and i need to make a condition to only do the union on the table when a condition is true. example:

$querysearch = mysql_query("
(SELECT id, 'Content' AS result, ...)

UNION

(SELECT id, 'Files' AS result, ...)

UNION

(SELECT postid, 'Categories' AS result, ...)

");

when $_GET['foo'] is either 'Content', 'Files, or 'Categories' i want just the results for that union, but when no $_GET['foo'] is present do the union on all 3 tables..as shown above. how can i do this?

thanks for any help.

coopster

2:16 am on Jun 2, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Write it out, just as you stated it.

if (!isset [php.net]($_GET['foo'])) { 
$querysearch = mysql_query("
(SELECT id, 'Content' AS result, ...)
UNION
(SELECT id, 'Files' AS result, ...)
UNION
(SELECT postid, 'Categories' AS result, ...)
");
}