Jump to content


Selecting from two db tables in one query?

  • Please log in to reply
2 replies to this topic

#1 Else

  • New Members
  • Pip
  • Newbie
  • 1 posts
  • LocationCleveland

Posted 08 June 2003 - 09:01 PM

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!


// 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.";





   echo "<font color=\'#000000\'><center>No reviews available!<center></font><br>n";




The second array returns $i[\'attach_id\'] null (inside the while loop).
All your base are belong to us.

#2 effigy

  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 09 June 2003 - 02:51 AM

do the tables have a common field you can join them on? i.e., primary key to foreign.
Regexp | Unicode Article | Letter Database

#3 mgm_03

  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts
  • LocationFort Worth, TX

Posted 10 June 2003 - 06:40 AM

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
Guru?...in my dreams!
Sorry Everybody


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users