I’m trying to create an e-commerce site which sells PC components using PHP and MySQL.
I’m using a database which has a table called ‘components’ which stores PC components with fields like ‘name’, ‘type’ etc. I have a field called ‘image’ as I was told it is better to store images in the file system rather than as a BLOB. The field contains the name of the image for that component (e.g. for Intel i7 2700k processor the image filed has inteli72700k/jpg). The image will be stored in ‘../images/products/’.
Now i’m trying to make my product list (i.e. a user clicked on ‘Processors’ and I am now trying to show the list of products we have, similar to overclockers.co.uk). I’m creating a table where the table heading is the name of the product and there is one row per product.
<table id="products">
<?php
//Connects to the DB, localhost is yourpc, root is the username and there is no password
$con = mysql_connect('localhost','root','');
//This is the database we want to access in phpMyAdmin
mysql_select_db('pctweeks');
$query = "SELECT * FROM component WHERE type = 'CPU'";
$query_run = mysql_query($query) or die(mysql_error($con));
if (mysql_num_rows($query_run) >= 1){
while($row = mysql_fetch_assoc($query_run)) {
echo "<th>{$row['name']}</th>" .
"<tr><td>{$row['image']}</td></tr>";
}
} else
{
echo 'No Products';
}
?>
</table>
The problem is the {$row['image']} part. I know I have to use an image tag but I don’t know how to insert the directory of the pictures before the $row['image'].
Cant you use the code like here: