This is the SQL table:
+---------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------+------+-----+---------+----------------+
| ID | int(11) | | PRI | NULL | auto_increment |
| Food | text | YES | | NULL | |
| foodId | int(11) | YES | | NULL | |
| Energy | int(11) | YES | | NULL | |
| Protein | double | YES | | NULL | |
| Fat | double | YES | | NULL | |
| Carbo | double | YES | | NULL | |
| Calcium | int(11) | YES | | NULL | |
| Iron | double | YES | | NULL | |
| Sodium | int(11) | YES | | NULL | |
| VitA | int(11) | YES | | NULL | |
| VitC | double | YES | | NULL | |
+---------+---------+------+-----+---------+----------------+
These are the foods which are in it:
+----+------------+--------+--------+---------+------+-------+---------+------+-
-------+------+------+
| ID | Food | foodId | Energy | Protein | Fat | Carbo | Calcium | Iron |
Sodium | VitA | VitC |
+----+------------+--------+--------+---------+------+-------+---------+------+-
-------+------+------+
| 1 | Cornflakes | 1 | 368 | 8.6 | 1.6 | 85.1 | 3 | 6.7 |
1160 | 0 | 0 |
| 2 | Weetabix | 2 | 340 | 11.4 | 3.4 | 70.3 | 33 | 7.6 |
360 | 0 | 0 |
| 3 | Muesli | 3 | 368 | 12.9 | 7.5 | 66.2 | 200 | 4.6 |
180 | 0 | 0 |
| 4 | Porridge | 4 | 374 | 10.9 | 9.2 | 66 | 52 | 3.8 |
9 | 0 | 0 |
| 5 | Milk | 5 | 65 | 3.2 | 3.9 | 4.6 | 103 | 0.1 |
50 | 56 | 1.5 |
| 6 | Sugar | 6 | 394 | 0 | 0 | 105.3 | 2 | 0 |
0 | 0 | 0 |
+----+------------+--------+--------+---------+------+-------+---------+------+-
This is the code which I have been trying to get to work - There are probably quite a few errors but you should be able to see what I am trying to do. Thanks
HTML>
<BODY>
<?php
if(isset($calc)):
?>
<Table><tr>
<td width=70><B>Energy (Kcals)</B></td>
<td width=70><B>Protein (g)</B></td>
<td width=70><B>Fat (g)</B></td>
<td width=70><B>Carbo (g)</B></td>
<td width=70><B>Calcium (g)</B></td>
<td width=70><B>Iron (mg)</B></td>
<td width=70><B>Sodium (mg)</B></td>
<td width=70><B>VitA (mmg)</B></td>
<td width=70><B>VitC (mg)</B></td></tr>
// IN THESE ROWS I WANT THE RESULTS TO BE SHOWN
<tr>
<td width=70></td>
<td width=70></td>
<td width=70></td>
<td width=70></td>
<td width=70></td>
<td width=70></td>
<td width=70></td>
<td width=70></td>
<td width=70></td></tr>
<?php
else:
// Set the page title and include the HTML header.
$page_title = 'Select the food amounts';
include_once ('templates/header.inc');
$dbcnx = @mysql_connect();
if(!$dbcnx) {
echo("<P>Unable to connect to the server</P>");
exit();
}
//select the food database
if(! @mysql_select_db("Foods")) {
echo("<P>Unable to locate the food database</P>");
exit();
}
$query = "SELECT * FROM breakfast";
echo '<br><table border="1" cellspacing="3" cellpadding="3" align="center"><tr>';
// Display all the URLs.
$result = mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
// Display each record.
echo "<td>{$row['Food']}</td>";
} // End of while loop.
echo '</tr>'; // Close the table row.
echo '<tr><td><input type=text name=cornamount></td>';
echo '<td><input type=text name=food1amount></td>';
echo '<td><input type=text name=food2amount></td>';
echo '<td><input type=text name=food3amount></td>';
echo '<td><input type=text name=food4amount></td>';
echo '<td><input type=text name=food5amount></td></tr></table><br>';
echo '<INPUT TYPE=SUBMIT NAME="calc" VALUE="calc">';
include_once ('templates/footer.inc'); // Require the HTML footer.
?>
</BODY>
</HTML>