Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

Hot to call an image from mysql database

images php coding issues or problems here.

Moderators: macek, egami, gesf

Hot to call an image from mysql database

Postby enzomuho » Sun Feb 05, 2012 11:28 pm

Hello to everyone.

Can someone give me a little help, i am new in PHP and i got stock in some php code.

I am trying to create a website which have some php code to call some data from mysql database
i have found some part of the php code in some other forum the code works perfect the only problem i have is that when i want to call the row of images i just gate the name of the image not the image as view " image.jpg"

the code i have is like below.

<?php
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("sherbime") or die(mysql_error());
$data = mysql_query("SELECT * FROM products")
or die(mysql_error());
Print "<table border=1 cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
echo "<th></th> <td>".$row['Image'] . "</td>";
Print "<th> Desktop:</th> <td>".$info['Desktop'] . "</td> ";
Print "<th>Model:</th> <td>".$info['Model'] . "</td> ";
Print "<th>Parameters:</th> <td>".$info['Parameters'] . "</td> ";
Print "<th>Price:</th> <td>".$info['Price'] . " </td></tr>";
}

Print "</table>";
?>

i am using wampserver, also have another question, where should i store my images to call from database??


thanks in advance Enzo
User avatar
enzomuho
New php-forum User
New php-forum User
 
Posts: 7
Joined: Sun Feb 05, 2012 11:12 pm

Re: Hot to call an image from mysql database

Postby rupali » Mon Feb 06, 2012 2:06 am

hi,

use image tag for display image on a web page.
in the given script the change which i have done it should be in bold letters.

<?php
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("sherbime") or die(mysql_error());
$data = mysql_query("SELECT * FROM products")
or die(mysql_error());
Print "<table border=1 cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
echo "<th>Image</th> <td><img src=".$row['Image'] . " height='100' width='100' /></td>";
Print "<th> Desktop:</th> <td>".$info['Desktop'] . "</td> ";
Print "<th>Model:</th> <td>".$info['Model'] . "</td> ";
Print "<th>Parameters:</th> <td>".$info['Parameters'] . "</td> ";
Print "<th>Price:</th> <td>".$info['Price'] . " </td></tr>";
}

Print "</table>";
?>


The answer to your question is that, to fetch from database, images are just only for display, and if you want to save, then you can make a link on each image so that it should open in another page (where you can put the code of saving images using move_uploaded_file function).
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA

Re: Hot to call an image from mysql database

Postby enzomuho » Mon Feb 06, 2012 3:03 am

thanks a lot rupali it worked :)
User avatar
enzomuho
New php-forum User
New php-forum User
 
Posts: 7
Joined: Sun Feb 05, 2012 11:12 pm

Re: Hot to call an image from mysql database

Postby enzomuho » Mon Feb 06, 2012 3:05 am

Well i was thinking... it is possible to click over the image and show his original size???? :?
User avatar
enzomuho
New php-forum User
New php-forum User
 
Posts: 7
Joined: Sun Feb 05, 2012 11:12 pm

Re: Hot to call an image from mysql database

Postby rupali » Tue Feb 07, 2012 2:04 am

Great :)

no, if you want to display the original size then do not mention height and width in image tag
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA

Re: Hot to call an image from mysql database

Postby enzomuho » Tue Feb 07, 2012 2:43 am

Yes but it will show me the original size of the image, i was thinking to show the embed image and if i click over than in a pop up window to get the original size, is that possible?
User avatar
enzomuho
New php-forum User
New php-forum User
 
Posts: 7
Joined: Sun Feb 05, 2012 11:12 pm

Re: Hot to call an image from mysql database

Postby rupali » Tue Feb 07, 2012 5:13 am

hi,
To display embed image in a pop window,
use jquery and if you are using hyperlink <a href=""> then it is just only display the original image in new tab or new window, so i suggest to you to use jquery there for display image in pop up window
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron