473,385 Members | 1,343 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,385 software developers and data experts.

fetch multiple image from mysql in php

i am trying to fetch all images which is store in my mysql database this is my code but not able to fetch please help

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. mysql_connect("localhost", "root", "") or die("Can not connect to database: ".mysql_error());
  3. mysql_select_db('brightweb') or die("Can not select the database: ".mysql_error());
  4.  
  5. $sql = "select * from portfolio";
  6.         // the result of the query
  7.         $result = mysql_query($sql) or die("Invalid query: "  .mysql_error());
  8.         // Header for the image
  9.         while ($rows = mysql_fetch_array($result))
  10.  
  11.         header('Content-type: image/jpg');
  12.         echo $row['image'];  
  13.  
  14.  
  15.  
  16. ?>
May 4 '13 #1
6 13420
Atli
5,058 Expert 4TB
How exactly are you expecting to use that script?

Normally when you fetch image data from a database, or pass an image file through PHP, then you do something along the lines of this in your HTML
Expand|Select|Wrap|Line Numbers
  1. <img src="fetchImage.php?id=1" alt="Image from PHP">
  2.  
Which calls the PHP page as an image to get the image data. The PHP script then fetches the image data from the database/file and passes it to the browser. - As far as the browser is concerned, there is absolutely no difference between calling a static JPEG image and calling a PHP script that returns JPEG image data.

Which brings me back to my original question: How are you going to be using a PHP script that returns data for multiple images? That would be no use in a normal <img> tag, as it would essentially just be read as a corrupted image.

If you want to build a page that displays all images stored in a MySQL table, you need to do that in two parts: The first part would create a list of <img> elements, one for each image, that queries a second PHP file with the ID of the image that <img> element is supposed to get. The second part would then be that PHP file, which would fetch that single image from the database and pass it's data back to the <img> tag.
May 4 '13 #2
i have already tried this one but this code not show any result
May 5 '13 #3
Atli
5,058 Expert 4TB
Did you try what I suggested in my last paragraph?

The one line of HTML I posted won't work with the kind of PHP script you posted. That was the point I was trying to make.
May 5 '13 #4
Exequiel
288 256MB
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. mysql_connect("localhost", "root", "") or die("Can not connect to database: ".mysql_error());
  3. mysql_select_db('brightweb') or die("Can not select the database: ".mysql_error());
  4.  
  5. $sql = "select * from portfolio";
  6.         // the result of the query
  7.         $result = mysql_query($sql) or die("Invalid query: "  .mysql_error());
  8.         // Header for the image
  9.         while ($rows = mysql_fetch_array($result))
  10. ?>
  11. <img src="locationoftheimage/<?php echo echo $row['image'].'.jpg'; ?>">
  12.  
  13.  
you can try that one, you need to specify the file extension of your image when displaying it in img tag. and also the location of the image need to specify to display it properly.
the img tag must be inside of your while loop.
May 8 '13 #5
Atli
5,058 Expert 4TB
The $row['image'] in his code, according to his first post, is not the location of a image file, it's the actual image data. What you are suggesting there assumes it's the name or location of a file on the hard-drive.
May 8 '13 #6
thank's sir my problem have been solved
May 11 '13 #7

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

Similar topics

1
by: Sean | last post by:
i am writing a class that visual demonstrates the result of changing the quality of a jpeg. the intention is to do this by saving the file and a selected quality, then reloading it to get an idea of...
1
by: rajbala.3399 | last post by:
Hai all, I need to get multiple image buttonsand wheni click on the image button it should display corresponding image on window and if i click another image button it is also display on same...
1
by: hemashiki | last post by:
hi i inserted an image in mysql,by using BLOB type i wan to fetch..can anyone tell me,how to do this
1
by: brothers | last post by:
I am intermediate user of PHP. I want to create mine search page which allows user to view one or more than one image. I can make the search page to view one image but i cannot views all the image in...
16
ribbo
by: ribbo | last post by:
What I need in a nutshell is a form that will allow me to upload multiple pictures (say 5) to my server while at the same time saving the names to the MySQL database. I would prefer it if the image...
3
Soniad
by: Soniad | last post by:
Hello, In stored procedure, i am using query that fetches 2 columns record but single row. i have used cursor to fetch single record. is there any way to fetch the record and put it in...
4
by: robin1983 | last post by:
Dear All, I am facing a problem when i display the data from mysql which i have inserted through textarea tag. I have a form where i copy and paste the details and submitted. But, when i fetch...
1
by: RAQUELIII | last post by:
HI! I MADE A STORED PROCEDURE BUT WHEN I CALL IT ONLY RETURN THE FIRST RECORD AS A MESSAGE, AND DOESNT RETURN ALL THE RECORDS THAT I QUERY. THIS IS THE CODE: CREATE PROCEDURE SCHEMA.PROCED21( OUT...
15
by: gaurav13477 | last post by:
i fetch single image . how i fetch multiple image. please send the code. img1.php <?php $con=mysql_connect('localhost','root',''); $d=mysql_select_db("test"); $q1="select * from cat ";...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.