Jump to content

[SOLVED] Union


aztec

Recommended Posts

Hello

 

Is it possible to extract a data field from a select statment and use it in a "second" union statement. A look at the code will probably explain a little better what I am trying to do.

 

$a_result = @mysql_query("SELECT id, first_name, surname FROM weston_gen_10 WHERE id='$page' or link_to_spouse='$page'
UNION SELECT id, first_name, surname FROM weston_gen_11 WHERE link_to_fid='$page'
UNION SELECT id, first_name, surname FROM weston_gen_9 WHERE fid=5 or 6 or 7 or 8" );

 

The variable $page is passed to the page that will be displayed and is a different number that is in the TITLE of all my pages.

 

The numbers 'fid=5 or 6 or 7 or 8 are all contained in the results of the first SELECT statement.

 

Without using a separate call to the database is it possible to extract that data and use it instead of the numbers in the second Union.

 

The code works but it is not flexible because the numbers change with each web page.

 

Is two calls to a database a bad thing because in effect I am making three selects at present.

 

Kind Regards

Link to comment
https://forums.phpfreaks.com/topic/99822-solved-union/
Share on other sites

$a_result = @mysql_query("SELECT id, first_name, surname FROM weston_gen_10 WHERE id='$page' or link_to_spouse='$page'
UNION SELECT id, first_name, surname FROM weston_gen_11 WHERE link_to_fid='$page'
UNION SELECT id, first_name, surname FROM weston_gen_9 WHERE fid IN
(SELECT id FROM weston_gen_10 WHERE id='$page' or link_to_spouse='$page') " );

Link to comment
https://forums.phpfreaks.com/topic/99822-solved-union/#findComment-510792
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.