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
https://forums.phpfreaks.com/topic/558-selecting-from-two-db-tables-in-one-query/
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.