Databases Reference
In-Depth Information
This is the PHP code to generate the HTML form:
// Yes; fetch the gift details a row at a time
while($row = @ mysqli_fetch_array($result))
// Compose the data for this gift into a row of form inputs in the table.
// Add a delete link in the last column of the row.
echo "\n<tr>" .
"\n\t<td>{$row["gift_id"]}</td>".
"\n\t<td><input name='description[{$row['gift_id']}]' ".
"value='{$row["description"]}' size='60' /></td>".
"\n\t<td><input name='quantity[{$row['gift_id']}]' ".
"value='{$row["quantity"]}' /></td>".
"\n\t<td><input name='color[{$row['gift_id']}]' ".
"value='{$row["color"]}' /></td>".
"\n\t<td><input name='shop[{$row['gift_id']}]' ".
"value='{$row["shop"]}' size='30' /></td>".
"\n\t<td><input name='price[{$row['gift_id']}]' ".
"value='{$row["price"]}' /></td>".
"\n\t<td><a href='{$_SERVER['PHP_SELF']}?action=delete&".
"gift_id={$row["gift_id"]}'>Delete</a></td>".
"\n</tr>";
In the last column of each table row, we create an HTML link to the same script with
a query string containing values for two variables: the action is set to delete , and the
gift_id is set to the ID of the gift displayed in the current row. Clicking on this link
will cause the script to delete the gift with that ID; we describe how this is done later
in this chapter.
A sample output of the while loop for two gifts—with IDs 6 and 10—is shown below:
<tr>
<td>6</td>
<td><input name='description[6]'
value='Avanti Twin Wall Mixing Bowls 2.8 Ltr' size='60' /></td>
<td><input name='quantity[6]'
value='2' /></td>
<td><input name='color[6]'
value='Silver' /></td>
<td><input name='shop[6]'
value='Myer' size='30' /></td>
<td><input name='price[6]'
value='41.65ea (83.30 total)' /></td>
<td><a href='edit.php?action=delete&gift_id=6'>Delete</a></td>
</tr>
<tr>
<td>10</td>
<td><input name='description[10]'
value='Baileys Comet 6 Ladder' size='60' /></td>
<td><input name='quantity[10]'
value='1' /></td>
<td><input name='color[10]'
value='Silver' /></td>
<td><input name='shop[10]'
value='Bunnings' size='30' /></td>
<td><input name='price[10]'
 
Search WWH ::




Custom Search