Jump to content

Selecting from two db tables in one query?


Else

Recommended Posts

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).

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.