General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 26th, 2004, 08:52 AM
cbunting cbunting is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 19 cbunting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How to show a default image if blob = 0 bytes?

Hello,
I am using the following code to display 1 image per listing, however, I can't seem to figure out how to display a default image from images/no_image.gif when no image was uploaded for that listing.

I have noticed in phpmysqladmin that the blob field shows as having 0 bytes if no image was uploaded. So is there a way to do an if check to see if the byte is 0?

Here is the image display code:
-----------
<?
$conn = mysql_connect(HOST,USER,PASS);
mysql_select_db(DB);
$tkey = "" . $key . "";
$strsql = "SELECT * FROM `listings` WHERE `id` = " . $tkey;
$rs = mysql_query($strsql, $conn) or die(mysql_error());
if (!($row = mysql_fetch_array($rs))) {
die("File not exists.");
}

echo $row["main_image"];

mysql_free_result($rs);
mysql_close($conn);
?>
---------------

I tried something like this but it didn't work. I'm not sure if this code is correct.

if( $row['main_image'] != "" )
{
echo $row["main_image"];
}
else {
echo "<img src=\"images/no_image.gif\" border=\"0\" width=\"130\" height=\"90\">";
}

Thanks for your time,
Chris

Reply With Quote
  #2  
Old January 26th, 2004, 09:18 AM
cbunting cbunting is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 19 cbunting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hello All,
This probably isn't the correct way to do this but I got a default image to show now just replacing the die( message with image code..

---------
$rs = mysql_query($strsql, $conn) or die(mysql_error());
if (!($row = mysql_fetch_array($rs))) {
die("<img src=\"images/no_image.gif\" border=\"0\" width=\"130\" height=\"90\">");
}

echo $row["main_image"];
mysql_free_result($rs);

--
What better way to do things.. haha.. I imagine that I have the most generic multiple image upload code that probably shouldn't be working at all but it does and now I have default images so if it works, don't fix it so they say.. haha.

Chris

Reply With Quote
  #3  
Old January 26th, 2004, 09:47 AM
cbunting cbunting is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 19 cbunting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Well, I thought it was working but I added a new listing without an image and it didn't show the default image.

Anyone have any ideas?

Thanks,
Chris

Reply With Quote
  #4  
Old January 26th, 2004, 09:51 AM
cbunting cbunting is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 19 cbunting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
For anyone else looking for multi-upload code, you may find this link helpful...

Chris

http://pear.php.net/package/HTTP_Upload

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > How to show a default image if blob = 0 bytes?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT