mysql_fetch_array and multiple tables

admin

Administrator
Staff member
I'm selecting information from a number of tables and using mysql_fetch_array to display them. My main table (object) contains a number of fields containing information on genes. One of my joined tables, re, contains literature references for the genes. There are a number of references per gene, each stored as a separate value in the re table.

Here's some code...

#--------------------------------------------

$query ="SELECT * FROM object,ec,re WHERE object.code LIKE '%arg%' AND object.code = ec.code AND object.code = re.code";

$result = mysql_query($query)
or die ("<br>Error doing select query on EC");

# Put data in an array
while ($row = mysql_fetch_array($result)) {

$ec = $row["ec"];
$code = $row["code"];
$type = $row["type"];
$na = $row["na"];
$co = $row["co"];
$ph = $row["ph"];
$sy = $row["sy"];
$pr = $row["pr"];
$cl = $row["cl"];
$lg = $row["lg"];
$ar = $row["ar"];
$lu = $row["lu"];
$lr = $row["lr"];
$ll = $row["ll"];
$re = $row["re"];

print("Code $code<br>");
print("Type $type<br>");
print("Name $na<br>");
print("Comments $co<br>");
print("Phenotype $ph<br>");
print("EC $ec<br>");
print("References $re");
print("<br><br>");
}


#--------------------------------------------

What happens here is that each set of gene data gets printed, but because there are multiple values in the re table for each gene code, the results get repeated again...

How do I print all of the re values for each code on the same line with the corresponding gene data set?

Thanks for taking a look!

Matt
 
Back
Top