p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Setting image code from a mysql request


Message #1 by Jefferis Peterson <jefferis@p...> on Mon, 23 Sep 2002 16:35:22 -0400
I'm using PHP.  I was only storing the relative link but not the html code
in the mysql datbase. I was trying to figure out how to load the image when
it the record is pulled in from a query...

Right now, it is displaying the relative link minus the html <img.src 
code. 

> I'm not very familiar with PHP, but I know it's similar to ASP.  You must
> have some PHP code that handles the HTML fromatting (tables, fonts, etc..)
> of your result page.  In that code you need to add the <IMG> tags.  It's
> not really a database issue and the HTML should, IMO, not be stored in the
> DB, I know wrox has several PHP lists that may be able to help you with the
> exact syntax for PHP.
> 
> http://p2p.wrox.com/php/
> 
> -Greg

 
~~~~~~~~~~~~
Jefferis Peterson, Pres.
Web Design and Marketing
http://www.PetersonSales.net
Tel .  xxx-xxx-xxxx
ICQ 19112253

http://www.Slippery-Rock.com - 7,000 hits per year

 

Message #2 by "Nikolai Devereaux" <yomama@u...> on Mon, 23 Sep 2002 13:52:12 -0700
Hi Jefferis,

Since your post to this list is based on a reply to your original post on some
other forum, can you be a bit more specific about what you're trying to do?


My impression is that you're storing a relative URL to an image (e.g.
"images/logo.gif") in a database, and you'd like to construct an <IMG> tag to
display that image in a page somewhere.

There couldn't be an easier thing to do in PHP.

$query = "SELECT rel_url, desc FROM images WHERE ...";
$result = db_query($query);

if($result)
{
  if($row = db_fetch_array($result, DB_ASSOC))
  {
    $desc = $row['desc'];
    $rel_url = $row['rel_url'];
  }
}
else  // image not found or some similar error...
{
   $desc = 'not found';
   $rel_url = 'images/not_found.jpg';
}

$img_tag = "<IMG src=\"{$rel_url}\" alt=\"{$desc}\" />\n";


Something like that, anyway...


nik

Message #3 by Jefferis Peterson <jefferis@p...> on Mon, 23 Sep 2002 20:06:59 -0400
Thanks Nik... 
 
 That's exactly right. Thank you.

Jeff

> From: "Nikolai Devereaux" <yomama@u...>
 > Hi Jefferis,
> 
> Since your post to this list is based on a reply to your original post on some
> other forum, can you be a bit more specific about what you're trying to do?
> 
> 
> My impression is that you're storing a relative URL to an image (e.g.
> "images/logo.gif") in a database, and you'd like to construct an <IMG> tag to
> display that image in a page somewhere.
> 
> There couldn't be an easier thing to do in PHP.
> 
> $query = "SELECT rel_url, desc FROM images WHERE ...";
> $result = db_query($query);
> 
> if($result)
> {

~~~~~~~~~~~~
Jefferis Peterson, Pres.
Web Design and Marketing
http://www.PetersonSales.net
Tel .  xxx-xxx-xxxx
ICQ 19112253

http://www.Slippery-Rock.com - 7,000 hits per year


  Return to Index