<?php
$hostname = "localhost";
$database = "hillcrestjewelers";
$username = "hcjewel";
$password = "SPark11ng";
$MYSQL = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database);

$itemdata = array("Item Number",
					"Primary Metal",
					"Secondary Metal",
					"Primary Color",
					"Secondary Color",
					"Item Type",
					"Sub Type",
					"Center Stone",
					"Center Stone Shape",
					"Center Stone Clarity",
					"Center Stone Color",
					"Center Stone Weight",
					"Side Stone",
					"Side Stone Shape",
					"Side Stone Clarity",
					"Side Stone Color",
					"Side Stone Weight",
					"Cost",
					"Retail"
);
$mysqlstring = 'SELECT * FROM `jewelery` WHERE ';
$mysqlstring = $mysqlstring.'`type` = \''.$type.'\' ';
if (isset($subtype)) {
	$mysqlstring = $mysqlstring.'AND (`subtype` = \''.$subtype.'\') ';
};
$mysqlstring = $mysqlstring.'AND (`metal` LIKE \''.$metal.'\') ';
if (isset($stone)) {
	$mysqlstring = $mysqlstring.'AND (`cstone` OR `sstone` = \''.$stone.'\')';
};
$data = mysql_query($mysqlstring);
$i = (mysql_num_rows($data) -1);
$l = 0;
if ($i >= 0) {
	while ($l <= $i && $i >= 0) {
		mysql_data_seek($data, $l);
		$row = mysql_fetch_array($data);
		$loop=0;
?>
	<table align="center" width="100%">
		<tr>
			<td align="left" width="48%">
				<a href="jewelery/<? echo($row[0]); ?>.jpg" target="_IMAGE"><img src="jewelery/<? echo($row[0]); ?>.jpg" width="320" height="240" border="0" /></a>
			</td>
			
			<td align="right" width="48%">
				<table align="center" width="100%" border="2" bordercolor="#996633">
				<? while($loop < 16) { ?>
					<tr>
						<td align="left" width="45%">
							<?  echo($itemdata[$loop]);?>
						</td>
						<td align="right" width="55%">
							<? echo($row[$loop]); ?>
						</td>
					</tr>
				<? $loop++;
				 }; ?>
				</table>
			</td>
		</tr>
	</table>
<?
	$l++;
	};
} else {
?>
	<table align="center" width="100%">
		<tr>
			<td>
				<p align="center">Sorry nothing to display at this time</p>
			</td>
		</tr>
	</table>
<? }; ?>