0

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..

3
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by xiiopao
2

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..

Edited by tomato.pgn: n/a

0

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..

0

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...

0

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

0

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 ?

0

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 =)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.