I'm just starting to figure out how to work with databases and I'm sure this question has been ask before but I have been unable to find an answer, and this is probably just a simple mistake on my part.
I have been able to get a basic database query to work but I am trying to figure out relational database queries.
Here's the error message I am getting:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /mysites/home/directory/test.php on line 21
Heres my code:
<table>
<?
//blanked out the following lines for security
$location = "";
$username = "";
$password = "";
$database = "";
$open_db = mysql_connect("$location","$username","$password");
if (!$open_db) die ("Could not connect MySQL");
mysql_select_db($database,$open_db) or die ("Could not open database");
$query = "
SELECT rel_FieldOne, rel_FieldTwo, rel_FieldThree, Some_Name, Some_Number, Other_Info, Date
FROM Table_One, Table_Two, Table_Three, Table_Four
WHERE Table_One.rel_FieldOne = Table_Two.Id_Num
AND Table_One.rel_FieldTwo = Table_Three.Id_Num
AND Table_One.rel_FieldThree = Table_Four.Id_Num";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
echo ("
<tr>
<td>$row[rel_FieldOne] $row[rel_FieldTwo]</td>
<td>$row[Some_Name]</td>
<td>$row[Some_Number]</td>
</tr>
");
}
mysql_close($open_db);
?>
</table>
now I know everything is working because when I change the query to the following it works fine.
$query = "
SELECT Some_Name, Some_Number, Other_Info, Date
FROM Table_One";
So I must assume that something is wrong with how I am setting up the relationships.
I think my database is setup right (phpMyAdmin helped a lot). I have configured the Table_Two, Table_Three, Table_Four tables so that each records id will auto increment and then I have taken those ids and placed them into the desired fields in rel_FieldOne, rel_FieldTwo, rel_FieldThree.
I am sure it's just a simple problem but the solution is evading me.