How to pull images from MySql database using PHP

General discussions related to php

Moderators: macek, egami, gesf

NabilChicago
New php-forum User
New php-forum User
Posts: 5
Joined: Sat Apr 05, 2003 7:51 pm
Location: Chicago
Contact:

How to pull images from MySql database using PHP

Postby NabilChicago » Sat Apr 05, 2003 7:59 pm

Hi,
I have a table in my database which is called raja_products, this table contains (productID, productPrice, productImage, productDescription).

productImage contains picture`s names of the products (eg, shoes.jpg). I already uploaded these pictures to a folder called images. What I`m looking for is a script that can display these images in my site.

Thank you[/url][/list]

User avatar
bezmond
Moderator
Moderator
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK
Contact:

Postby bezmond » Sun Apr 06, 2003 12:11 am

Code: Select all

<?
mysql_connect("host","username","password) or die("Couldn't connect to mysql, whoops!");
mysql_select_db("databasename") or die("Couldn't open the database, did ya screw up?");
$query = "SELECT * FROM raja_products";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
$imagefile = $row["productImage"];

***you can insert variables for the other fields here too***
?>
<img border="0" src="imagesfolder/<? echo $imagefile ?>" width="640" height="480">
<? } ?>


Hope that works,
Andrew

NabilChicago
New php-forum User
New php-forum User
Posts: 5
Joined: Sat Apr 05, 2003 7:51 pm
Location: Chicago
Contact:

Thank you

Postby NabilChicago » Sun Apr 06, 2003 11:38 pm

:lol:
Thank you very much, it works.

User avatar
bezmond
Moderator
Moderator
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK
Contact:

Postby bezmond » Mon Apr 07, 2003 6:18 am

Cool. Your welcome

Andrew


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 1 guest