aztec Posted April 6, 2008 Share Posted April 6, 2008 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 More sharing options...
aztec Posted April 6, 2008 Author Share Posted April 6, 2008 Hello Does anyone know the answer to the last part Is two calls to a database a bad thing because in effect I am making three selects at present. This may help me to sort out the rest of the inquiry, Regards Link to comment https://forums.phpfreaks.com/topic/99822-solved-union/#findComment-510709 Share on other sites More sharing options...
Barand Posted April 6, 2008 Share Posted April 6, 2008 $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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.