I am using MySQL 4.0 so I can't use subqueries or this would be really easy. Also, postgresql is not an option. What I need to do is get the data from the following information into a single array and I am not figuring it out.
I have 2 tables: system_table and user_table.
system_table looks like:
system | tech1 | tech2
Where system is the name of the system and tech1 and tech2 or the userID's from user_table.
user_table looks like:
TID | realname
Where TID is the techID and realname is, well, the real name.
So I need to perform a query that gets the following results:
system | tech1_realname | tech2_realname
I have built the folllowing code to start with...
$system_query = "SELECT * FROM system_table ORDER BY system";
$system_result = mysql_query($system_query, $anykey) or die ("System Query Error: " . mysql_error());
$system_array = array();
$tech1_array = array();
$tech2_array = array();
$i = 0;
while ($rows = mysql_fetch_array($system_result, MYSQL_ASSOC))
{
$system_array[$i] = $rows['system'];
$query = "SELECT realname FROM user_table WHERE TID = " . $rows['tech1'];
$result = mysql_query($query, $anykey) or die ("Tech1 Fetch Error: " . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$tech1_array[$i] = $row['realname'];
mysql_free_result($result);
$query = "SELECT realname FROM user_table WHERE TID = " . $rows['tech2'];
$result = mysql_query($query, $anykey) or die ("Tech2 Fetch Error: " . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$tech2_array[$i] = $row['realname'];
mysql_free_result($result);
$i++;
}
But I don't know if I need to write this differently, or how I need to combine the arrays to get what I want. Thanks for any help.