Hi,
I'm a bit of a noob with PHP.
I am trying to retrieve information from multiple tables with the following code
<?php
function check_input($id)
{
// Stripslashes
if (get_magic_quotes_gpc())
{
$id = stripslashes($id);
}
// Quote if not a number
if (!is_numeric($id))
{
$id = "'" . mysql_real_escape_string($id) . "'";
}
return $id;
}
include 'private/auth.php'; //sql login file
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$database");
$id=$_GET["id"];
$id=check_input($id);
$query="SELECT * FROM products WHERE id=$id";
$result=mysql_query($query);
while($row = mysql_fetch_array($result))
{
echo "<table>";
echo "<tr><td colspan=2><h3>" . $row['Name'] . " - " . $row['Referance'] . "</h3></td></tr>";
echo "<tr><td><p>Other Details</p></td><td><p>" . $row['Details'] . "</p></td></tr></table>";
}
{
$id2=$row['id'];
$query2="SELECT * FROM transactions WHERE ProdId='$id2' limit 10";
$result2=mysql_query($query2);
echo "Last 10 Hires:<table>";
while ($trans = mysql_fetch_array($result2));
{
$DocketId=$trans['DocketId'];
$query3="SELECT * FROM dockets WHERE id='$DocketId'";
$result3=mysql_query($query3);
while ($DocketInfo = mysql_fetch_array($result3))
{
echo "<tr><td><a href='docket.php?id=" . $DocketId . "'>" . $DocketId . "</a></td>";
$query4="Select * FROM customers WHERE id='$DocketInfo[CustId]'";
$result4=mysql_query($query4);
while ($CustInfo=mysql_fetch_array($result4))
{
echo "<tr><td><a href='docket.php?id=" . $DocketInfo['CustId'] . "'>" . $CustInfo['Name'] . "</a></td></tr>";
}
}
}
echo "</table>";
echo $query2;
echo $query3;
echo $query4;
}
mysql_close($con);
?>
My Problem is that all the queries seem to be executed at the same time.
The query in $query2 is using information retrieved from $query, and the query in $query3 is using information from $query2, and the query in $query4 is using information retrieved in $query3, this means $query2, $query3, and $query4 is not working.
Any help would be greatly apreciated, it may be that I am doing this completely wrong!
Thanks in advance!