Hello all
I am currently trying to teach myself some PHP and mySQL work in order to build a DB driven website.
I have a table in my database which stores information about a product eg (product name, price, description, image(set as a blob))
What I want to do is list all the items in this table in a webpage with the image showing following by the name and price of the item under it, something similar to the way Game.co.uk website displays their product information
I also would like when an item has been clicked on to show a new page with all the item's details.
Are there ay templates any knows of or has which I could go by as I am struggling to get this working
Kind Regards
Akin
You'd need 3 pages. The products page which displays all products, the image which will display the image, and the product details page which will show all the details about the product.
Code:<?PHP
//display all products
$query = mysql_query("SELECT * FROM `products`") or die(mysql_error());
while($row=mysql_fetch_assoc($query)) {
//format the output
echo '<a href="fullProduct.php?id='.$row['id'].'"><img src="image.php?id='.$row['id'].'">'.$row['name'].'</a>';
}Code:<?PHP
//display image
$id = $_GET['id'];//FILTER!!
$query = mysql_query("SELECT `image` FROM `products` WHERE `id`='$id'") or die(mysql_error());
while($row=mysql_fetch_assoc($query)) {
$im = imagecreatefromstring($row['image']);
if ($im !== false) {
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
}
else {
echo 'An error occurred.';
}
}Code:<?PHP
//display full product
$id = $_GET['id'];//FILTER!!
$query = mysql_query("SELECT * FROM `products` WHERE `id`='$id'") or die(mysql_error());
while($row=mysql_fetch_assoc($query)) {
//format the output
}
Excellent thats worked like a charm thanks alot mate just another quick thing
When im formatting the output I want each image to appear side by side/horizontally with the details of the items below the image so far I have this
...//display all products
$query = mysql_query("SELECT * FROM tblItems") or die(mysql_error());
while($row=mysql_fetch_assoc($query)) {
//format the output
echo '<table border="1" cellpadding="10">
<tr>
<td><a href="fullProduct.php?id='.$row['id'].'"><img src="image.php?id='.$row['id'].'"> </td>
</tr>
<td>'.$row['name'].'</a><br />£'.$row['price'].'</td>
</tr>
</table>';
}
This displays the details below the images as I want but each record is shown vertically, how would I get the images to appear side by side?
Thanks
Try this
Code:<?PHP //display all products
$query = mysql_query("SELECT * FROM tblItems") or die(mysql_error());
while($row=mysql_fetch_assoc($query)) {
//format the output
echo '<table border="1" cellpadding="10">
<tr>
<td><a href="fullProduct.php?id='.$row['id'].'"><img src="image.php?id='.$row['id'].'"></a></td>
<td><a href="fullProduct.php?id='.$row['id'].'">'.$row['name'].'</a><br />£'.$row['price'].'</td>
</tr>
</table>';
}
I have tryed that already, that displays the image in one column with the details in a column next to it
I have been toying with it for some time now and cannot get it to display the images in one row and the details in a row below
Oh, sorry. I misunderstood.
I think you just forgot to close the tr tag.Code:<?PHP //display all products
$query = mysql_query("SELECT * FROM tblItems") or die(mysql_error());
while($row=mysql_fetch_assoc($query)) {
//format the output
echo '<table border="1" cellpadding="10">
<tr>
<td><a href="fullProduct.php?id='.$row['id'].'"><img src="image.php?id='.$row['id'].'"></a></td>
</tr>
<tr>
<td><a href="fullProduct.php?id='.$row['id'].'">'.$row['name'].'</a><br />£'.$row['price'].'</td>
</tr>
</table>';
}
That is still producing the images below one another and not side by side
The code was exactly the same as I had and it does seem to make sence but displays as soo
[IMAGE]
[Image details]
[IMAGE]
[Image details]
[IMAGE]
[Image details]
Where it should be
[IMAGE] [IMAGE] [IMAGE]
[Image details] [Image details] [Image details]
![]()
Code:<?PHP //display all products
$query = mysql_query("SELECT * FROM tblItems") or die(mysql_error());
echo '<table border="1" cellpadding="10"><tr>';
while($row=mysql_fetch_assoc($query)) {
//format the output
echo '<td><a href="fullProduct.php?id='.$row['id'].'"><img src="image.php?id='.$row['id'].'"></a><br />'.
'<a href="fullProduct.php?id='.$row['id'].'">'.$row['name'].'</a><br />£'.$row['price'].'</td>';
}
echo '</tr></table>';
}
Thats the one
There was an extra } in there but took it out and worked!
Thanks alot it is very much appreciated!!
![]()
How would I be able to specify a new row to start? as currently the data outputs in one continious row.
I have put the table in a div tag and the width has been set to 600px yet the table continues past the tags specified width and carrys on showing in one continous line
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks