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

How will I show Image from the batabase?

images php coding issues or problems here.

Moderators: macek, egami, gesf

How will I show Image from the batabase?

Postby Imranertaza » Mon Feb 21, 2011 7:39 am

Hi all
You know, I am in problem because I can't show Image from mysql database at my page. Have their anyone to give me the perfect answer.
Thanks all
Imranertaza
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon Feb 21, 2011 12:07 am

Re: How will I show Image from the batabase?

Postby Nullsig » Tue Feb 22, 2011 9:33 am

How are you storing the image in the database?

Are you just storing the URL to an image stored elsewhere?
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: How will I show Image from the batabase?

Postby phmyway » Tue Mar 01, 2011 12:31 am

I hope you do not have a problem of inserting images in a table. You can get thumbnails or gallery of pictures from your database. However, note that I use a separate folder to keep the images and their pointers in the database. For example, the following code shows you that I have a table named audio_pics with all the columns as image_id and image_date. While fetching the image id and date from the table, it also anchors the image from a subfolder cd4car_images/thumbs/.

<?php
//get the thumbs
$getpic = mysql_query("SELECT * FROM audio_pics")
or die(mysql_error());
$records = mysql_num_rows($getpic);

while($rows = mysql_fetch_array($getpic)) {
extract($rows);
echo "<tr>\n";
echo "<td><a href=\"../cd4car_images/thumbs/$image_id.jpg\" >";//this href is anchored to the image below
echo "<img src=\"../cd4car_images/thumbs/$image_id.jpg\" >";
echo "</a></td>\n";
echo "<td>" . $image_date . "</td>\n";
echo "</tr>\n";

}
if ($records == 0) echo "No results found. Please try again";
?>

Let me hear from you, if I have to explain more.
phmyway
New php-forum User
New php-forum User
 
Posts: 6
Joined: Mon Feb 28, 2011 11:45 pm

Re: How will I show Image from the batabase?

Postby egami » Wed Mar 02, 2011 10:28 am

First and foremost.
mysql_fetch_array will fetch your data, with a numberic array starting at 0.
so your array would look something like this..

$row['0'] = "Something";
$row['1'] = "Something else";
$row['2'] = "mypicture.jpg";


mysql_fetch_assoc will fetch your data with the table fields as the array key..
ie.

$row['id'] = "Something";
$row['else'] = "Something else";
$row['image'] = "mypicture.jpg";


...


Then you would call the variable like so..

<image src="/the/directory/$row[image]" border="0" />
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: How will I show Image from the batabase?

Postby Nullsig » Thu Mar 03, 2011 9:08 am

actually mysql_fetch_array allows you to reference row data by EITHER the index or the field name.

mysql_fetch_assoc only allows for field name and mysql_fetch_row only allows for index. This makes these two slightly faster than mysql_fetch_array.

In order of speed it is:

fetch_row is faster than fetch_assoc which are both faster than fetch_array.
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI


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