I've tried to go about this but don't seem to be able to get it going.
layout is this
I have a few tables, the first is the
mastertable
username
car1id
car2id
car3id
car4id
car1table
car1id
car1note
car1value
car1deprec
car2table
car2id
car2note
car2value
car2deprec
car3table and car4table follow the same pattern above
Values have been submitted to the tables, I wish to draw up a table that accesses the above info for all 4 cars
Car Notes | Car values | Car Depreciation
I'm quite confused in which direction to head. I've tried using functions including calls to the database inside the functions but I don't get success.
for example
$query = "SELECT * FROM mastertable WHERE username='$username'";
$result = mysql_query($query) or die("error in query: $query".mysql_error());
$rowid = mysql_fetch_array($result);
echo "<table width=\"750\" border=\"2\" cellspacing=\"3\" cellpadding=\"3\">";
echo "<tr>";
echo "<td>Car Notes</td>";
echo "<td>Car Value</td>";
echo "<td>Car Depreciation</td>";
echo "</tr>";
function tables($quer, $cartable, $resul, $carid, $rows, $id)
{$quer = "SELECT * FROM $cartable WHERE $carid='$rowid[$id]'";
$resul = mysql_query($quer) or die("error in query: $quer".mysql_error());
$rows = mysql_fetch_array($resul);
echo "<tr>";
echo "<td>".$rows[1]."</td>";
echo "<td>".$rows[2]."</td>";
echo "<td>".$rows[3]."</td>";
echo "</tr>";
}
tables ($query1, car1table, $result1, car1id, $row1, 1);
tables ($query2, car2table, $result2, car2id, $row2, 2);
tables ($query3, car3table, $result3, car3id, $row3, 3);
tables ($query4, car4table, $result4, car4id, $row4, 4);
Am I'm going in the wrong direction? or is my coding incorrect?
I've now also tried this
$queryit = "SELECT * FROM mastertable WHERE username='$username'";
$resultit = mysql_query($queryit) or die("error in query: $queryit".mysql_error());
$data = mysql_fetch_array($resultit);
echo "<br />$data[1] <br />";
echo "should be 2 above";
function getdata($quer, $cartable, $resul, $carid, $rows, $id){
$quer = "SELECT * FROM $cartable WHERE $carid='" . $data[$id] . "'";
$resul = mysql_query($quer) or die("error in query: $quer".mysql_error());
$rows = mysql_fetch_array($resul);
}
getdata($query1, car1table, $result1, car1id, $row1, 1);
echo "$query1 <br />";
echo "$rows[1] <br />";
echo "$rows[2] <br />";
echo "Or nothing here";
echo "<table width=\"750\" border=\"2\" cellspacing=\"3\" cellpadding=\"3\">";
echo "<tr>";
echo "<td>Car Note</td>";
echo "<td>Car Value</td>";
echo "<td>Car Depreciation</td>";
echo "</tr>";
echo "<tr>";
for ($i=1; $i <= 3; $i++){
echo "<td>$row1[$i]</td>";
}
echo "</table>";