Databases Reference
In-Depth Information
In normal operation, there will be gift descriptions in the system; depending on how
the function was called, we run a query to list all the unreserved gifts (those that have
their username field set to NULL ), or all the gifts reserved by the current user (those that
have their username field set to $_SESSION['username'] ):
// If we're showing the available gifts, then set up
// a query to show all unreserved gifts (where username IS NULL)
if ($show_user_selection == SHOW_UNRESERVED_GIFTS)
$query = "SELECT * FROM gifts WHERE username IS NULL ORDER BY description";
else
// Otherwise, set up a query to show all gifts reserved by
// this user
$query = "SELECT * FROM gifts WHERE username = '".
$_SESSION['username']."' ORDER BY description";
// Run the query through the connection
if (($result = @ mysqli_query($connection, $query))==FALSE)
showerror($connection);
If the query doesn't retrieve any results, we display a message indicating that no unre-
served gifts are available or that the user has not reserved any gifts, depending on which
list we're showing:
// Did we get back any rows?
if (@ mysqli_num_rows($result) == 0)
{
// No data was returned from the query.
// Show an appropriate message
if ($show_user_selection == SHOW_UNRESERVED_GIFTS)
echo "\n<h3><font color=\"red\">No gifts left!</font></h3>";
else
echo "\n<h3><font color=\"red\">Your Basket is Empty!</font></h3>";
}
else
{
// Yes, so show the gifts as a table
}
If we do find some gifts to show, we compose an HTML table and iterate through the
results to display the gift attributes:
echo "\n<table border=1 width=100%>";
// Create some headings for the table
echo "\n<tr>" .
"\n\t<th>Quantity</th>" .
"\n\t<th>Gift</th>" .
"\n\t<th>Colour</th>" .
"\n\t<th>Available From</th>" .
"\n\t<th>Price</th>" .
"\n\t<th>Action</th>" .
"\n</tr>";
// Fetch each database table row of the results
while($row = @ mysqli_fetch_array($result))
 
Search WWH ::




Custom Search