Hi Guys,
Im slowly getting to grips with php. Here is my problem.
I have a page http://www.richard-howells.co.uk/final_project/products.php that displays all product categories from a:
DB table called 'product_types'
With fields:
product_type_description (PK)
product_type_image
When you click on one of the category images, I want to be able to view all products within that category.
DB table for the procucts is called 'products'
With fields:
product_id (PK)
product_type_description (FK)
product_name
product_description
product_price
product_main_image
product_thumbnail_image
PHP CODE:
<html>
<head>
<title>Goldcast Computers</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="/style_sheets/styles.css" rel="stylesheet" type="text/css">
</head>
<body topmargin="1">
<table width='780' class='mainoutsideborder' align='center' border='0' cellpadding='0' cellSpacing='2' >
<tr>
<td colspan='2'><?php include('includes/header.inc'); ?></td> </tr>
<tr bgcolor='#5382a8'>
<td colspan='2' class='primnavcell'><?php include('includes/primary_nav.inc'); ?></td>
</tr>
<td width='660' height='151' bgcolor='' rowspan='2'>
<?php
include('includes/misc.inc');
$per_row = 4;
$query = mysql_query('SELECT product_type_description AS catname, product_type_image AS catimg FROM product_types ORDER BY product_type_description');
if(!$query)/*if $result not available */
{die("Couldn't execute query. Reason: ".mysql_error());}
echo '<table >';
$i = 0;
while ($row = mysql_fetch_array($query)) {
if (!$i) {
echo '<tr>';
$i = $per_row;
}
echo '<td class="logindescriptions"><a href="viewproducts.php?id=".$row[product_type_description]."\"><img src="images/thumbnail_images/'
. $row['catimg'] . '" border="0"></a><br />' . $row['catname'] . '</td> ';
if (!--$i) {
echo '</tr> ';
}
}
if ($i) {
echo '<td colspan="' , $i , '"></td></tr>';
}
echo '</table>';
?>
<td width='150' height='50'class='loginbox' align='center' valign="middle">Log In OR Register</td>
</tr>
<tr>
<td width='150' class="productsrelatedbox">products are displayed in here which are related to the users profile</td>
</tr>
<tr>
<td colspan='2' class="footercell"><?php include('includes/footer.inc'); ?></td>
</tr>
</table>
As you can see I want to call the page that displays the products avaialable fo that category 'viewproducts.php'.
I think to solve this i need to have an id stored through PHP in this case 'should it be' product_type_description as this is the primary key in product types and a foreign key in the products table. In other words this is the relationship.
Im after some sort of help on how to acheive this goal
Any help greatly appreciated.
Regards and Good Day
Richard