Script 19.6 Browse Prints

Output
title home page view the prints view your cart

Artist Print Name DescriptionImagePrice
Walt Disney creativeprints $666.00
Saddam Hussain warprints $444.00
Martin Luther King Peaceful prints $220.00
John Lennon psychadelic prints $450.00
Richard Nixon dirty prints $600.00
Elvis Presley Princely prints $200.00
Malcolm X powerful prints $250.00

© 2014 Copyright...
Source
<?php # Script 19.6 - browse_prints.php
// This page displays the available prints (products).

// Set the page title and include the HTML header:
$page_title = 'Browse the Prints';
include ('includes/header.html');

require (CONNECT_OOP);
 
// Default query for this page:
$q = "SELECT sc_artists.artist_id, CONCAT_WS(' ', first_name, middle_name, last_name) AS artist, print_name, price, image_name, description, print_id FROM sc_artists, sc_prints WHERE sc_artists.artist_id = sc_prints.artist_id ORDER BY sc_artists.last_name ASC, sc_prints.print_name ASC";

// Are we looking at a particular artist?
if (isset($_GET['aid']) && filter_var($_GET['aid'], FILTER_VALIDATE_INT, array('min_range' => 1))  ) {
	// Overwrite the query:
	$q = "SELECT sc_artists.artist_id, CONCAT_WS(' ', first_name, middle_name, last_name) AS artist, print_name, price,image_name, description, print_id FROM sc_artists, sc_prints WHERE sc_artists.artist_id=sc_prints.artist_id AND sc_prints.artist_id={$_GET['aid']} ORDER BY sc_prints.print_name";
}

// Create the table head:
echo '<table border="0" width="90%" cellspacing="3" cellpadding="3" align="center">
	<tr>
		<td align="left" width="20%"><b>Artist</b></td>
		<td align="left" width="20%"><b>Print Name</b></td>
		<td align="left" width="25%"><b>Description</b></td>';
echo '<td align="left" width="20%"><b>Image</b></td>';
echo '<td align="right" width="15%"><b>Price</b></td>
	</tr>';

// Display all the prints, linked to URLs:
$r = mysqli_query ($link, $q);
while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) {

	// Display each record:
	echo "\t<tr>
		<td align=\"left\"><a href=\"index.php?chapter=19&script=19.6&aid={$row['artist_id']}\">{$row['artist']}</a></td>
		<td align=\"left\"><a href=\"index.php?chapter=19&script=19.7&pid={$row['print_id']}\">{$row['print_name']}</a></td>
		<td align=\"left\">{$row['description']}</td>";
	echo "<td align=\"left\"><img width=50 height=50 src=\"".SITE_URL."/exercises/19/images/{$row['image_name']}\" /></td>";
	echo "<td align=\"right\">\${$row['price']}</td>
	</tr>\n";

} // End of while loop.

echo '</table>';
mysqli_close($link);
include ('includes/footer.html');
?>