Output Images from Database - Problem - help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tinoda
Forum Commoner
Posts: 33
Joined: Mon Dec 29, 2008 3:32 am

Output Images from Database - Problem - help

Post by tinoda »

I saved my image path to a database and tried to retrieve the actual images using the code below.
<?php
$db = odbc_connect("asaa","asaa_user","asas");
$sql = "SELECT id, url, time FROM fotogalerie";
$res = odbc_exec($db, $sql);
while ($row = odbc_fetch_array($res)) {
print($row['id'].",".$row['url'].",".$row['time']."\n");
}
odbc_free_result($res);

odbc_close($db);
?>
Instead of getting the images that I need I get the output below:
101,/gg/en/pple/007_old/image1.jpg, 102,/gg/en/pple/007_old/image1.jpg,
101,/gg/en/pple/007_old/image2.jpg, 102,/gg/en/pple/007_old/image2.jpg,
101,/gg/en/pple/007_old/image3.jpg, 102,/gg/en/pple/007_old/image3.jpg,

where am I going wrong? Thank for your help.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Output Images from Database - Problem - help

Post by susrisha »

This is where you have gone wrong i think.

Code: Select all

 
print($row['id'].",".$row['url'].",".$row['time']."\n");
 
What you are doing is just printing the url of the image as a string. It doesnot give any images.

try to put an image tag like this=>

Code: Select all

 
print($row['id']);
?>
<img src="<?php echo $row['url']; ?>" size=(your image size)/>
<?php 
echo $row['time']."\n";
 
tinoda
Forum Commoner
Posts: 33
Joined: Mon Dec 29, 2008 3:32 am

Re: Output Images from Database - Problem - help

Post by tinoda »

thanks but now its giving me this output:

Code: Select all

101101 >102102 >101101 <102102 >101101 <102102 <101101 <102102 <101101 <102102
the flex brackets that i have put are actually triangles that r out put and if i place my mouse pointer on the triangles it displays a message with my image path and also says unresolved link. If i click the triangle it also outputs this code: <?php echo $row['url']; ?>
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Output Images from Database - Problem - help

Post by susrisha »

try this one
must be some problem with the url linking

Code: Select all

 
<IMG height="image height" src="<?php echo (your url from db); ?>" width="imagewidth">
 
Post Reply