|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
For anyone else looking for multi-upload code, you may find this link helpful...
Chris http://pear.php.net/package/HTTP_Upload |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > How to show a default image if blob = 0 bytes? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|