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

Pulling jpeg name images out of MySQL onto PHP page

MS
I am new to PHP and MySql. What I would like to do is have my PHP page
pull the name of an image (jpeg, bmp, etc.) out of MySQL and display
image from another directory. I don't want the actual image saved in
the DB, just the name.

I have the connection established from the Web Page to MySql, all I
want is how to display the image part. Does anyone have any
straightforward code to show me how to do this? Is there a better way
that is not too complicated? Remember, I am a newbie.

Thanks.

Jun 6 '06 #1
2 1909
Message-ID: <11**********************@y43g2000cwc.googlegroups .com> from
MS contained the following:
I have the connection established from the Web Page to MySql, all I
want is how to display the image part. Does anyone have any
straightforward code to show me how to do this? Is there a better way
that is not too complicated? Remember, I am a newbie.


Assuming you are storing image names and alt text, this should work

$path="/images/"; // absolute path to images directory
$sql="SELECT imagefield, alt_text FROM imagetable";
$result=mysql_query($sql);
while($myrow=mysql_fetch_array($result)){
echo "<img src='$path".$myrow['imagefield']."'
alt='".$myrow['alt_text']."'><br>";
}

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jun 6 '06 #2

MS wrote:
[snip]
straightforward code to show me how to do this? Is there a better way
that is not too complicated? Remember, I am a newbie.


Straightforward? Boy, am not sure if you want to display this image
inline or as an image src...

For inline, you need to open the image file:

$Image = imagecreatefromjpeg($ImageName.jpg)

..... do stuff with the image here if you wish...

header("content-type: image/jpeg")
imagejpeg($Image)
?>

Image already exists as a .jpg on disk NOT in a database, create a link
to it.

$Query = "select DirFilePath from FileDatabase where
imagename='ImageName.jpg'";
$db = $chk->query($Query);
.....db error glue stuff here.
$info = $chk->fetchrow();

for ease of use, combine your DirFilePath with ImageName.jpg
( /usr/local/images/imagename.jpg ) or something like that.
<img src="/usr/local/images/imagename.jpg">
..... more html/php code here.

your results may vary!

Jun 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: JT | last post by:
is there a command in asp to get the name of the current page? furthermore, is there a way to retrieve the name of the current page within an 'included' file (not the name of the included page,...
1
by: Srikumar Srinivasan | last post by:
I am trying to find out if there is a way to paste images to web page forms much like you can paste text. The reason being is we have a web based help desk site and users submit issues using a...
3
by: Andy Kasotia | last post by:
On the client once the user clicks the Submit button....in my code the following javascript function kicks off... onclick="return SubmitForm('frmCurrBuildings', 'CurrBuildings.asp', c_iLOADNEW,...
0
by: PontiMax | last post by:
Hi, in the Page_Load method of my web page I want to loop through all images of that page in order to resolve their path. How can that be done? Note: I want to extract simple HTML images, not...
23
by: paul | last post by:
HI! How so get the name of the present page into a variable? I need it because I need to attach it to a path so I can make others link to me. My pages are in iframes. Paul
1
by: jd | last post by:
Question from an ASP.Net newbie: using ASP.Net 2.0, how can I iterate over all the images in a page? The reason: I need to tweak the URLs for each image (I need to insert an "order id" field so...
3
by: Dhananjay | last post by:
Hello everyone Do you have any idea about how to generate a tool which will extract the contents and images from html page.or do you have any resources then let me know. i am using VS 2005...
5
by: Jim in Arizona | last post by:
I built a webpage using vb.net (.net 2.0) that creates a form letter. This letter pulls data from a database. Although I populate the address with the person's full name, which comes from the name...
2
by: amritpalpathak | last post by:
my html file has the coding following.. <html> <head> <script language="javascript" src="/var/www/external.js"></script> <script langauge="javascript">
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.