I am trying to create a master/detail page (Dreamweaver Mx, PHP, mysql) using two tables (fauna, regiones) and I am unable to get all the fields to appear on the detail page mainly because I am unsure on how to write the queries. Here's what I have:
1. I have created the following JOINED recordset on the MASTER page
SELECT *
FROM fauna, regiones
WHERE fauna.id=regiones.id
2. Now here is what I am not sure about...what do I put as the parameter to link to the detail page
detail.php?RECID=<?php echo $row_recordset['???']; ?>
3. And finally on the DETAIL page, how do I write the query that would permit me to view fields from both tables
varRECID = $_GET[???]
SELECT *
FROM fauna,regiones
WHERE ? = varRECID
I hope I have supplied enough clear information for you to respond.
Many thanks
Jim
Master/detail page - using multiple tables
Moderator: General Moderators
Here is an example of what we did (modified and simplified), which you should be able to follow for your example:
Our code looks something like:
Being that this is the detail page you would make a call to it similar to:
<a href="details.php?pass_id=$id">Details Page</a>
pass_id is simply a variable. So let's say you do a query on the fauna table and display the results. Since you have the ID field of that table, simply assign it to the variable pass_id which you can see we used the variable in 2 places.
1. as a parameter to calling the details page.
2. in the SQL statement in the details page.
Many times our NON_details.php page looks something like:
<table>
<tr>
<th>field 1</th>
<th>field 2</th>
<th>Details Page</th>
</tr>
<tr>
<td>$field1</td>
<td>$field2</td>
<td><a href="details.php?pass_id=$id">View Details Page</td>
</tr>
</table>
Which of course I left out all the code to get the db info this is simply showing how we setup calls to the details.php page. it puts it into a nice formatted table, etc. And you can see where the PHP code is obviously.
This may not be the best way to handle this but it seems fairly straight forward and it works!!
Our code looks something like:
Code: Select all
$sql = "SELECT fauna.field1, fauna.field2, regiones.f1, regiones.f2 FROM fauna, regiones WHERE fauna.id = regiones.id AND fauna.id = '$pass_id' ";
$result = mysql_query($sql, $link) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$field1 = $rowї"$field1"];
$field2 = $rowї"$field2"];
$f1 = $rowї"$f1"];
$f2 = $rowї"$f2"];
echo "$field1<br>";
echo "$field2<br>";
echo "$f1<br>";
echo "$f2<br>";
}Being that this is the detail page you would make a call to it similar to:
<a href="details.php?pass_id=$id">Details Page</a>
pass_id is simply a variable. So let's say you do a query on the fauna table and display the results. Since you have the ID field of that table, simply assign it to the variable pass_id which you can see we used the variable in 2 places.
1. as a parameter to calling the details page.
2. in the SQL statement in the details page.
Many times our NON_details.php page looks something like:
<table>
<tr>
<th>field 1</th>
<th>field 2</th>
<th>Details Page</th>
</tr>
<tr>
<td>$field1</td>
<td>$field2</td>
<td><a href="details.php?pass_id=$id">View Details Page</td>
</tr>
</table>
Which of course I left out all the code to get the db info this is simply showing how we setup calls to the details.php page. it puts it into a nice formatted table, etc. And you can see where the PHP code is obviously.
This may not be the best way to handle this but it seems fairly straight forward and it works!!