hi there im new to php and im currently building my website .,it's more like an online store and i would like my products to be listed in a gridview., i have a database and my only problem is how to display the images .., i've already displayed some info like the id and some description ., ive been searching the web for the right codes and tutorials that could help me about this but nothing seem to suit my site..,

my database contains: petid(int), petname(varchar),birthdate(date), image(blob)

here is my connection.php

<?php
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '';
    $db = 'store';

    $conn = mysql_connect($dbhost,$dbuser, $dbpass);
    mysql_select_db($db);
?>

then here is my code inserted in an html page to retrieve the database contents

<?php
                  include 'includes/connection.php' ;

                    $query = ("SELECT * FROM pets");
              
                    $result = mysql_query($query);
              
                  

                    while($dog = mysql_fetch_array($result)){
                        $petid = $dog ['petid'];
                        $petname = $dog ['petname'];
                        $Birthdate = $dog ['Birthdate'];
                        
                        echo "<h3>" . $dog['petid'] ."</h3>";
                        echo "<P>" . $dog['petname'] ."</P>";
                        echo "<P>" . $dog['Birthdate'] ."</P>";

                    }
                ?>

any help would be appreciated :$ or if anyone here who have any alternative on displaying the image... ive heard about image pointers stored in the database would be much easier but i dont know how it works..

See you can work this out in one way....store all images in a folder and in database add location of image (either relative or absolute)...
and then just display ie using the below code...

<?php
                  include 'includes/connection.php' ;
 
                    $query = ("SELECT * FROM pets");
 
                    $result = mysql_query($query);
 
 
 
                    while($dog = mysql_fetch_array($result)){
                        $petid = $dog ['petid'];
                        $petname = $dog ['petname'];
                        $Birthdate = $dog ['Birthdate'];
 
                        echo "<h3>" . $dog['petid'] ."</h3>";
                        echo "<P>" . $dog['petname'] ."</P>";
                        echo "<P>" . $dog['Birthdate'] ."</P>";
                        echo "<img src='".$dog['image']."' alt='dog' width='200' height='200' />";
                    }
                ?>

Hope this is what you were looking for...
PS-If your problem is solved mark the thread as solved....
Click on this to mark the thread as solved..

tomato.pgn ...
do you mean i will change the blob data type to varchar then put something like "C:\wamp\www\myproj\images\pets\pup1.jpg" to the image value?

sorry im really new to this..

yes that is what i am telling you...change it to varchar...
and you don't have to give complete location of image ...you can use relative location...
i.e.,"./images/pets/pup1.jpg"....
Hopefully it's clear...

yes it is thanks =) .., but i've tried it and my image didn't appear ... what appeared is a box with an 'x' mark ...

just put the last name in the database, as in imagename.jpg - it then should work :)

and if that doesnt work, i will put a php code into here to help you get the image the way i did, you using php mysql as in phpmyadmin - university server or uni server as it knownto do database ?

i figured it out!!! thanks tomato.pgn =)

tnx for the reply rhiang1984 =) the problem is my path... something with the slashes ... anyways the code worked and finally got my image display on the page thanks gusys =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.