Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 15th, 2004, 12:02 PM
Authorized User
 
Join Date: Jun 2003
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default HELP - Displaying Images from mysql


Hi,

I'm successfully retrieving records from a mysql table. One of the fields in this table holds the url to an image eg :

"http://localhost/lists/images/img.gif"

The record is displaying a broken image link. The code im using to write the table looks like:

while ($row=mysql_fetch_array($mysql_result))
{
$id=$row["id"];
$image=$row["image_url"];
$var_1=$row["gift_type"];
$var_2=$row["desc"];
$var_3=$row["url"];
$var_4="<a href='$var_3'>Select</a>";

echo $image;
echo "<br>";

echo "<TR align=\"center\"><TD><img source=\"$image\"\"></></TD><TD>$var_1</TD><TD$var_2</TD><TD>$var_4</TD></TR>";
}
}

mysql_close($connection);

?>
</TABLE>

As i have said, the records are being displayed fine - Just no images!!!!!

If anyone can help I will be very grateful!!!

TIA

Tim

Tim
__________________
Tim
 
Old March 15th, 2004, 04:49 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

This is really messed up...

echo "<TR align=\"center\"><TD><img source=\"$image\"\"></></TD><TD>$var_1</TD><TD$var_2</TD><TD>$var_4</TD></TR>";

This should be:

echo "<TR align=\"center\"><TD><img src=\"$image\"></TD><TD>$var_1</TD><TD>$var_2</TD><TD>$var_4</TD></TR>";

Noticed what I added in red and I took out the silly-looking </> and the extra \" (which was probably what was causing your problems)

Hope this helps,

----------
---Snib---
----------
 
Old March 16th, 2004, 04:37 AM
Authorized User
 
Join Date: Jun 2003
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Worked a treat!! Excellent!! Many thanks for your help Snib!!

Tim
 
Old March 17th, 2004, 09:16 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Note for reference: </> is a valid SGML tag that's a shorthand for "Close the last opened tag", but it's NOT valid in HTML or XML. You need to explicitly name the tags you're closing in these markup languages.


Take care,

Nik
http://www.bigaction.org/
 
Old January 26th, 2005, 01:10 AM
Registered User
 
Join Date: Jan 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello
I know that I'm repling very late to this topic but, your doing exactly what I want to do.
Hi,
I'm successfully retrieving records from a mysql table. One of the fields in this table holds the url to an image eg :

"http://localhost/lists/images/img.gif

I created the table and I can sucessfully retrieve all the text records. I'll take the advice of the articles on image storage and not store my images in the databse itself. But, how do I store a hyperlink like you discussed table then use PHP to retrieve the image along with its corresponding text
Thank you
Capt D

 
Old January 26th, 2005, 03:09 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Depending on what you're doing, alter this code to your desire:

Code:
//right now, $image_url should be the URL to your image
//and $image_txt should be the corresponding text

echo "<img src='$image_url' alt='$image_txt'/>";
Is this something like what you need?

hth,

-Snib - http://www.snibworks.com
Where will you be in 100 years?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying images...... kethireddy435 ASP.NET 2.0 Professional 0 September 16th, 2007 09:25 PM
Displaying images stored in MySQL through in PHP trufla PHP Databases 3 May 2nd, 2006 04:55 AM
Images not displaying Penn_Clark Dreamweaver (all versions) 3 February 21st, 2006 12:59 PM
Displaying images inbox Classic ASP XML 2 May 4th, 2005 03:08 AM
displaying images from mySql DB in html cmcmillan.schillers Beginning PHP 1 October 5th, 2004 03:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.