<?php
// query db
$sql = "SELECT category.id as category_pk, category_id, products.* from category, products WHERE products.id = category.category_id AND category.id = category_id"; // from category get id
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
$row = mysql_fetch_assoc($result);
echo "<h2>" . $row['category_id'] . "</h2>";
} else {
echo "Something is wrong!";
}
}
?>
<div class="datadivleftcontent">
<?php
// query db
$sql = "SELECT product_image, products.* FROM product_image, products WHERE product_image.product_id = products.id AND product_image.product_id = products.id"; // from products get id
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
while ($row = mysql_fetch_assoc($result)) { //initial the loop
echo "<h4>" . $row['name'] . "</h4>"; // echo date results as format "h4"
echo "<p>" . $row['description'] . "</p>"; // echo content as p format "body text"
echo "<h5>Measurements: " . $row['measurements'] . "</h5>"; // echo content as p format "body text"
echo "<a href='img/products/{$row['filename']}' rel='lightbox' title='{$row['name']}'>";
echo "<img src='img/products/thumbnails/{$row['filename']} 'alt='{$row['name']}' title='{$row['name']}' width='173' height='136'></a>";
}
} else {
echo "Something is wrong!";
}
}
?>
Hi,
Firstly many thanks for all your help and support it is very much appreciated. I am finding this quiet difficult trying to sort out, I am not so familiar with backend mysql,php programming but i am getting by thanks to your help.
OK this is what I’ve done so far:
The DB:
category:
id (pk, auto increment)
category_id (index)
products:
id (fk to category_id, cascade)
name (index)
description
measurements
product_image:
product_id (fk to name, cascade)
filename
thumbnail
Now, I have menu (list item) were you can select the type of category linking to product_range.php:
<?php
// query db
$sql = mysql_query ("SELECT * FROM `category` ORDER BY ID ASC");
// echo linked result from db
if($resource and !is_bool($resource)) {
$row = mysql_fetch_assoc($resource);
}
while ($row = mysql_fetch_assoc($sql)){
echo "<a href='product_range.php?id={$row['category_id']}' "; echo ($fullpath == "product_range.php?category_id={$row['category_id']}") ? 'id="select"' : ''; echo ">" . ($row['category_id']) . "</a>";
}
?>
This is the code for the product_range.php
<?php include ("include/head.php"); ?>
<?php // db connect
$link = mysql_connect('localhost', 'root', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo '';
mysql_select_db("wp");
?>
<body>
<?php include ("include/header.php"); ?>
<div class="wrapper">
<?php include ("include/topnav.php"); ?>
<!-- data div -->
<div class="datadiv">
<div class="datadivleft">
<?php
// query db
if (isset($_GET['id'])) {
$sql = "SELECT category.id as category_pk, category_id, products.* from category, products WHERE products.id = category.category_id AND category.id = ?" . mysql_real_escape_string($_GET['id']) . "'"; // from category get id
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
$row = mysql_fetch_assoc($result);
echo "<h2>" . $row['category_id'] . "</h2>";
} else {
echo "Something is wrong!";
}
}
}
?>
<div class="datadivleftcontent">
<?php
// query db
if (isset($_GET['id'])) {
$sql = "SELECT products_image.* FROM products_image, products WHERE products_image.id = products.name AND products_image.id = ?" . mysql_real_escape_string($_GET['id']) . "'"; // from products get id
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
while ($row = mysql_fetch_assoc($result)) { //initial the loop
echo "<h4>" . $row['name'] . "</h4>"; // echo date results as format "h4"
echo "<p>" . $row['description'] . "</p>"; // echo content as p format "body text"
echo "<h5>Measurements: " . $row['measurements'] . "</h5>"; // echo content as p format "body text"
echo "<a href='img/products/{$row['filename']}' rel='lightbox' title='{$row['name']}'>";
echo "<img src='img/products/thumbnails/{$row['filename']} 'alt='{$row['name']}' title='{$row['name']}' width='173' height='136' /></a>";
}
} else {
echo "Something is wrong!";
}
}
}
?>
</div>
</div>
</div>
<!-- end -->
<?php include ("include/showcase.php"); ?>
<?php include ("include/btmcontent.php"); ?>
</div>
<?php include ("include/footer.php"); ?>
</body>
</html>
Now at present i cannot get any data echoed from the DB i,ve tried sourcing out the syntax as mention, I must be doin something wrong?