Fetch data from multiple MySQL tables

Posted by Jon McIntosh on Stack Overflow See other posts from Stack Overflow or by Jon McIntosh
Published on 2010-04-13T05:53:26Z Indexed on 2010/04/13 6:03 UTC
Read the original article Hit count: 413

Filed under:
|

My two tables look like this:

       TABLE1                      TABLE2
+--------------------+      +--------------------+
|field1|field2|field3|  and |field2|field4|field5|
+--------------------+      +--------------------+

I am already running a SELECT query for TABLE1, and assorting all of the data into variables:

$query = "SELECT * FROM TABLE1 WHERE field2 = 2";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);    
  if((!is_bool($result) || $result) && $num_rows) {
   while($row = mysql_fetch_array($result))
    {
   $field1 = $row['field1'];
   $field2 = $row['field2'];
   $field3 = $row['field3'];
    }
  }

What I want to do is get the data from 'field4' on TABLE2 and add it to my variables. I would want to get field4 WHERE field2 = 2

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql