473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to display 5 pictures stored in mysql using while loop.

Hello Sirs/madam
i have 5 picture store in mysql , and now i want to display these picture on the page ,using while loop ., in php.
please let me know through very very simple code.
thanking you.
best regards.
ikram
Aug 2 '07 #1
13 11248
pbmods
5,821 Expert 4TB
Heya, ikram. Welcome to TSDN!

You posted this in the PHP Articles section. I'll go ahead and move it to the PHP Forum where an Expert will be more likely to find it.

Changed thread title to better describe the problem.
Aug 2 '07 #2
kovik
1,044 Expert 1GB
Is the binary data actually saved in the database, or just the filenames?
Aug 2 '07 #3
Is the binary data actually saved in the database, or just the filenames?
Hello sir.
these pictures stores as blob in mysql. and i wnt to display these all pictures through while loop. i will understand very very simple code.

thanks.
ikram
Aug 3 '07 #4
Tarantulus
114 100+
Hello sir.
these pictures stores as blob in mysql. and i wnt to display these all pictures through while loop. i will understand very very simple code.

thanks.
ikram
Ikram,

by the sound of it you'll just need to loop through the mysql_result array

try:
Expand|Select|Wrap|Line Numbers
  1. $sql="SELECT imagename FROM yourtable";
  2. $runsql=mysql_query($sql);
  3. $i=0;
  4. $len=mysql_numrows($runsql);
  5.  
  6. while($i<$len){
  7. $image=mysql_result($runsql,$i);
  8. echo("<IMG SRC=\"$image\"></IMG>
  9. }
obviously you need to replace "imagename" with the name of your SQL field and "yourtable" with the name of the table

my coding is a bit sloppy so maybe someone else may give you a cleaner answer, but as far as I can gather that is what you want
Aug 3 '07 #5
gauravgmbhr
107 100+
Ikram,

by the sound of it you'll just need to loop through the mysql_result array

try:
Expand|Select|Wrap|Line Numbers
  1. $sql="SELECT imagename FROM yourtable";
  2. $runsql=mysql_query($sql);
  3. $i=0;
  4. $len=mysql_numrows($runsql);
  5.  
  6. while($i<$len){
  7. $image=mysql_result($runsql,$i);
  8. echo("<IMG SRC=\"$image\"></IMG>
  9. }
obviously you need to replace "imagename" with the name of your SQL field and "yourtable" with the name of the table

my coding is a bit sloppy so maybe someone else may give you a cleaner answer, but as far as I can gather that is what you want

try this link and see how the while loop is used with mysql_fetch_row()
http://in2.php.net/mysql_fetch_row
Aug 3 '07 #6
kovik
1,044 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. $sql="SELECT imagename FROM yourtable";
  2. $runsql=mysql_query($sql);
  3. $i=0;
  4. $len=mysql_numrows($runsql);
  5.  
  6. while($i<$len){
  7. $image=mysql_result($runsql,$i);
  8. echo("<IMG SRC=\"$image\"></IMG>
  9. }
The images are sored in the database, so the <img> tag wouldn't work that way. Also, FYI, you don't need a counter variable ($i), or the number of rows.
Aug 3 '07 #7
kovik
1,044 Expert 1GB
In order to display data from your database as an image, you'll need to create a file dedicated to retrieving the images and use it to display.

i.e.

[php]// image.php
header('Content-Type: image/jpeg');

// Check if it's been given an image to load
if(!isset($_GET['id']))
{
echo file_get_contents('someDefaultImage.jpg');
}
else
{
// Get the data
$result = mysql_query('SELECT `imageData` FROM `imageTable` WHERE `id` = " . (int)$_GET['id'] . ";");
$data = mysql_fetch_object($result);

// Echo the data
echo $data->imageData;
}[/php]

And then, call it in your other files like this:

[html]<img src="path/to/image.php?id=1" />[/html]

You could easily turn that into a while loop where you increment the id to use.
Aug 3 '07 #8
Tarantulus
114 100+
Wow, I try to help and I get schooled! wasn't expecting that :)
Aug 3 '07 #9
kovik
1,044 Expert 1GB
Wow, I try to help and I get schooled! wasn't expecting that :)
Hehe. Well, it's a good thing that you did. If you were to continue retrieving results in that manner, you'd be wasting valuable memory.
Aug 4 '07 #10
Ikram,

by the sound of it you'll just need to loop through the mysql_result array

try:
Expand|Select|Wrap|Line Numbers
  1. $sql="SELECT imagename FROM yourtable";
  2. $runsql=mysql_query($sql);
  3. $i=0;
  4. $len=mysql_numrows($runsql);
  5.  
  6. while($i<$len){
  7. $image=mysql_result($runsql,$i);
  8. echo("<IMG SRC=\"$image\"></IMG>
  9. }
obviously you need to replace "imagename" with the name of your SQL field and "yourtable" with the name of the table

my coding is a bit sloppy so maybe someone else may give you a cleaner answer, but as far as I can gather that is what you want
Hello sir.
i see your code became very happ because of very smple code. but sir try this , it doesn't work. i write the whole code is.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4. mysql_connect('localhost','root','')
  5. or die ("connection can't be established");
  6. mysql_select_db("test")
  7. or die("Data Base Can't be selected");
  8.  
  9. $sql="SELECT imagename FROM pix";
  10. $runsql=mysql_query($sql);
  11. $i=0;
  12. $len=mysql_numrows($runsql);
  13.  echo $len;
  14. while($i<$len)
  15. {
  16.  
  17. $image=mysql_result($runsql,$i);
  18.  
  19. echo "(<IMG SRC=\"$image\"></IMG>;
  20.  
  21. }
  22.  
  23. ?>
please you try this byself and then inform from the correct one.
thanking you.
best regards .
ikram
Aug 4 '07 #11
Hello sir.thank you very much.
sir can you write me the complet programing code so that i display the 5 pictures saved in mysql. sir for this you also write the following codes.

1 - code for table where my pictures are stores.
2- retrive the pictures through loop from mysql (sir write complete program)
3- display this on the other page (pleae write complete program)
sir you write these codes for me, and also try by you rself to test this.

i mean you write the whole program so i copy this from here and paste in my note pade and this should work . i will set the database connection no proble.
thanking you.
ikram


thanking you sir.


In order to display data from your database as an image, you'll need to create a file dedicated to retrieving the images and use it to display.

i.e.

[php]// image.php
header('Content-Type: image/jpeg');

// Check if it's been given an image to load
if(!isset($_GET['id']))
{
echo file_get_contents('someDefaultImage.jpg');
}
else
{
// Get the data
$result = mysql_query('SELECT `imageData` FROM `imageTable` WHERE `id` = " . (int)$_GET['id'] . ";");
$data = mysql_fetch_object($result);

// Echo the data
echo $data->imageData;
}[/php]

And then, call it in your other files like this:

[html]<img src="path/to/image.php?id=1" />[/html]

You could easily turn that into a while loop where you increment the id to use.
Aug 4 '07 #12
pbmods
5,821 Expert 4TB
Heya, ikram.

TSDN members are expected to write their own code. We're happy to help you out if you have specific questions, but you can't realistically expect someone to do your coding for you on a free forum.
Aug 4 '07 #13
kovik
1,044 Expert 1GB
sir can you write me the complet programing code so that i display the 5 pictures saved in mysql. sir for this you also write the following codes.

1 - code for table where my pictures are stores.
2- retrive the pictures through loop from mysql (sir write complete program)
3- display this on the other page (pleae write complete program)
sir you write these codes for me, and also try by you rself to test this.

i mean you write the whole program so i copy this from here and paste in my note pade and this should work . i will set the database connection no proble.
How much are you going to pay me for it? I don't work for free.
Aug 5 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: NotGiven | last post by:
I am researching the best place to put pictures. I have heard form both sides and I'd like to know why one is better than the other. Many thanks!
0
by: JakeC | last post by:
Hey all, I'm currently redesigning a website that a friend and I started about a year ago. It is a daily surf report so when choosing the best script/language to use for the new design, I found...
3
by: RAllsopp | last post by:
I have a client who would like to have several pictures associated with one system. I have read about storing only the pathname to save OLE overhead and have set-up a form for my client to...
12
by: Wadim Grasza | last post by:
I want to store and display (on a form or a report) multiple pictures per record in an access database. The pictures are not stored within the database. They are stored as files and the database...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
0
by: Bruno Barberi Gnecco | last post by:
I'm using stored procedures in a PHP site, with mysql. I'm having problems with stored procedures. Of the two I'm using, one works all the time, consistently. The other works correctly, but the...
9
by: blessblessbless | last post by:
Hey guys, I am creating a code out of bits and pieces I found in somebody else's code, so I am not entirely sure how it behaves. <IMG SRC="picture.php?ID=1029&THUMB=yes"> picture.php: <?...
1
by: Ian | last post by:
I have an Access 2000 database in which I display many pictures on reports, the pictures are not embedded, the database just stores the path to where the pictures are stored. When I select Gifs,...
46
by: OldBirdman | last post by:
What a mess this question is. I have spent 2 weeks trying to make it concise and clear, and I can't. I do not have the vocabulary for the question. I cannot even TITLE it correctly. Here is my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.