Else Posted June 8, 2003 Share Posted June 8, 2003 Hello. I have been searching with no prevail about this for weeks. I want to select some info from one table, as well as some different info from another, for use within one array. I say one array because when I used two it seemed to cancel one array out. I\'ve looked into the UNION operator, but it didnt work. Someone told me it was disabled in PHP for security issues or something. The current code for the query is below. If anyone can offer any advice, please do. I really appreciate it! <?php // MySQL Connection Information $db_server = "******"; $db_username = "******"; $db_password = "******"; $db_name = "******"; $link = mysql_connect($db_server, $db_username, $db_password) or die(mysql_error()); mysql_select_db($db_name, $link); $sql_topic = mysql_query("SELECT title, starter_name, starter_id, tid, description FROM ibf_topics WHERE forum_id=\'13\'", $link) or die(mysql_error()); if(mysql_num_rows($sql_topic) > 0) { while($t = mysql_fetch_array($sql_topic)) { $sql_attach = mysql_query("SELECT attach_id FROM ibf_posts WHERE topic_id=\'$t[\'tid\']\'", $link) or die(mysql_error()); $i = mysql_fetch_array($sql_attach); echo "In the actual page all the array vars are outputed here, displaying new article info."; } } else { echo "<font color=\'#000000\'><center>No reviews available!<center></font><br>n"; } mysql_close($link); ?> The second array returns $i[\'attach_id\'] null (inside the while loop). Quote Link to comment https://forums.phpfreaks.com/topic/558-selecting-from-two-db-tables-in-one-query/ Share on other sites More sharing options...
effigy Posted June 9, 2003 Share Posted June 9, 2003 do the tables have a common field you can join them on? i.e., primary key to foreign. Quote Link to comment https://forums.phpfreaks.com/topic/558-selecting-from-two-db-tables-in-one-query/#findComment-1874 Share on other sites More sharing options...
mgm_03 Posted June 10, 2003 Share Posted June 10, 2003 as the previous post indicates you need a common key. with mySQL I believe you want to use JOIN to get data from two tables simultaneously. The Visual Quickstart reference books show examples of this Quote Link to comment https://forums.phpfreaks.com/topic/558-selecting-from-two-db-tables-in-one-query/#findComment-1907 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.