Databases Reference
In-Depth Information
{
// Display the gift data as a table row
echo "\n<tr>" .
"\n\t<td>{$row["quantity"]}</td>" .
"\n\t<td>{$row["description"]}</td>" .
"\n\t<td>{$row["color"]}</td>" .
"\n\t<td>{$row["shop"]}</td>" .
"\n\t<td>{$row["price"]}</td>";
// Display a link to allow an unreserved gift to be added or
// a reserved gift to be removed...
echo "\n</tr>";
}
echo "\n</table>";
In the last column of each row, we show a link to “Add to Shopping List” if we're
displaying unreserved gifts, or a link to “Remove from Shopping List” if we're display-
ing gifts reserved by the user:
// Are we showing the list of gifts reserved by the
// user?
if ($show_user_selection == SHOW_UNRESERVED_GIFTS)
// No. So set up an embedded link that the user can click
// to add the gift to their shopping list by running
// action.php with action=add
echo "\n\t<td><a href=\"action.php?action=add&" .
"gift_id={$row["gift_id"]}\">Add to Shopping List</a></td>";
else
// Yes. So set up an embedded link that the user can click
// to remove the gift from their shopping list by running
// action.php with action=remove
echo "\n\t<td><a href=\"action.php?action=remove&" .
"gift_id={$row["gift_id"]}\">Remove from Shopping list</a></td>";
The links include a query string to specify the action to perform (
add
an unreserved gift
or
remove
a reserved gift) and the ID of the gift to process; for example, we might have
a link:
<a href="action.php?action=add&gift_id=10">Add to Shopping List</a>
Clicking on the link calls the
action.php
script with this action and gift ID. We describe
the operation of this script in the next section.
Selecting and Deselecting Gifts
Users add gifts to their shopping list or remove them by clicking on links in the
list.php
page. The links call the
action.php
script with the gift ID and the
action
pa-
rameter set to
add
or
remove
. For
add
, the script attempts to reserve the gift with the
specified
gift_id
for the current guest. Similarly, for
remove
, the script attempts to