 |

rasbro
User
Apr 28, 2008, 3:48 PM
Post #1 of 13
(494 views)
Shortcut
|
|
IF image THEN ...
|
Can't Post
|
|
How do I display some text ONLY if an image is uploaded/present? Example: IF <?php if ($upload['hasThumbnail']): ?> THEN <br /><span>Click to view larger image</span> Thanks, Brian
|
|
|  |
 |

Dave
Staff
/ Moderator

Apr 28, 2008, 5:16 PM
Post #2 of 13
(493 views)
Shortcut
|
|
Re: [rasbro] IF image THEN ...
[In reply to]
|
Can't Post
|
|
Hi Brian, try this:
<?php if ($upload['hasThumbnail']): ?> ... <br /><span>Click to view larger image</span> <?php endif; ?> And you can display something if there is no image like this:
<?php if ($upload['hasThumbnail']): ?> ... <br /><span>Click to view larger image</span> <?php else: ?> Sorry, no image! <?php endif; ?> Hope that helps! Dave Edis - Senior Developer interactivetools.com
|
|
|  |
 |

rasbro
User
Apr 28, 2008, 7:43 PM
Post #3 of 13
(491 views)
Shortcut
|
Okay, this is kind of what I'm looking for, except I need more fine tuning... What do I put if I don't want to include the text for each image. So for example, I only want this line, <br /><span>Click to view larger image</span> to be added once. Here is what I am working with now, which returns up to four lines if I have all four images uploaded: <?php foreach (getUploads($options['tableName'], 'other_images', $record['num']) as $upload): ?> <?php if ($upload['hasThumbnail']): ?> <a href="<?php echo $upload['urlPath'] ?>"><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="<?php echo $upload['filename'] ?>" title="<?php echo $upload['info1'] ?>" /></a> <?php endif ?> <?php endforeach ?> <?php foreach (getUploads($options['tableName'], 'other_images', $record['num']) as $upload): ?> <?php if ($upload['hasThumbnail']): ?> <p id="otherimages-clicklarger">Click on small photos to enlarge</p> <?php endif ?> <?php endforeach ?> Thanks, Brian
|
|
|  |
 |

rasbro
User
Apr 28, 2008, 7:47 PM
Post #4 of 13
(489 views)
Shortcut
|
Also, I am looking for a way to return an image and not just text, except the image is not uploaded via CMS Builder. I am trying to display a "Sorry, No Image" image when there is not an image uploaded to represent the product. Here is what I have: <?php foreach (getUploads($options['tableName'], 'thumbnail_image', $record['num']) as $upload): ?> <?php if ($upload['hasThumbnail']): ?> <img src="<?php echo $upload['thumbUrlPath'] ?>" width="75" height="75" alt="inset photo" /> <?php else: ?> <img src="/images/NoImage-thumbnail2.jpg" width="75" height="75" alt="inset photo" /> <?php endif ?> <?php endforeach ?> It doesn't work the way I have it currently. Thanks, Brian
|
|
|  |
 |

Dave
Staff
/ Moderator

Apr 29, 2008, 8:56 AM
Post #5 of 13
(469 views)
Shortcut
|
|
Re: [rasbro] IF image THEN ...
[In reply to]
|
Can't Post
|
|
Hi Brian, Do you have a mockup html page that shows the effect or design you're going for? That might help us get there quicker. >What do I put if I don't want to include the text for each >image. So for example, I only want this line, <br /> ><span>Click to view larger image</span>to be added once. If you only want to print one image, you can break out for a foreach loop (and stop looping over additional images) with the break function, like this: <?php break; ?> Just put that after the text you want displayed. >I am trying to display a "Sorry, No Image" image when there >is not an image uploaded to represent the product. Here is >what I have ... It doesn't work the way I have it currently. Try replacing this line:
<?php foreach (getUploads($options['tableName'], 'thumbnail_image', $record['num']) as $upload): ?> With these lines:
<?php $uploads = getUploads($options['tableName'], 'thumbnail_image', $record['num']); ?> <?php foreach ($uploads as $upload): ?> Then you'll be able to test if there was any images _after_ your foreach loop like this:
<?php $uploads = getUploads($options['tableName'], 'thumbnail_image', $record['num']); ?> <?php foreach ($uploads as $upload): ?> <?php if ($upload['hasThumbnail']): ?> <img src="<?php echo $upload['thumbUrlPath'] ?>" width="75" height="75" alt="inset photo" /> <?php endif ?> <?php endforeach ?> <?php if (count($images) == 0): ?> <img src="/images/NoImage-thumbnail2.jpg" width="75" height="75" alt="inset photo" /> <?php endif ?> Let me know it goes! Dave Edis - Senior Developer interactivetools.com
|
|
|  |
 |

rasbro
User
May 2, 2008, 2:15 PM
Post #6 of 13
(411 views)
Shortcut
|
Dave, I tried your suggestions but it did not work. If you take a look at www.owenequipmentsales.com/product.php/1-1/ you will see that the text "Click on small photos to enlarge" appears below the main product image, but there are no small photos featured. I need an IF/THEN statement that will detect when no small photos are uploaded and then NOT display the text. So only display the text when small photos are uploaded. Let's take care of this one first and then I will address the other IF/THEN statement issue regarding the display of the "Sorry, No Image" image when main product image not uploaded. I appreciate your help with this! Thanks, Brian
|
|
|  |
 |

Dave
Staff
/ Moderator

May 2, 2008, 2:30 PM
Post #7 of 13
(408 views)
Shortcut
|
|
Re: [rasbro] IF image THEN ...
[In reply to]
|
Can't Post
|
|
Hi Brian, So you want it to show "Click on small photos..." only once if there is any images uploaded? Is that right? Try this:
<?php if (count($images) > 0): ?> Click on small photos to enlarge <?php endif ?> And feel free to attach your viewer if you need more help and I'll take a look at your code. Dave Edis - Senior Developer interactivetools.com
|
|
|  |
 |

rasbro
User
May 2, 2008, 2:43 PM
Post #8 of 13
(405 views)
Shortcut
|
Dave, that worked to remove the text when other images are not uploaded but now I get an error when there are other images uploaded, as with this page: http://www.owenequipmentsales.com/product.php/14-23/ Notice: Undefined variable: images in /.../public_html/include-ProductRecordInsert.php on line 47 See the include file attached which contains the viewer code. Thanks, Brian
|
|
Attachments:
|
include-ProductRecordInsert.php
(4.30 KB)
|
|
|  |
 |

Dave
Staff
/ Moderator

May 2, 2008, 4:02 PM
Post #9 of 13
(401 views)
Shortcut
|
|
Re: [rasbro] IF image THEN ...
[In reply to]
|
Can't Post
|
|
Thanks, try this:
<td colspan="2" id="sumimg-otherimages"><br /> <?php $otherImages = getUploads($options['tableName'], 'other_images', $record['num']); ?> <?php foreach ($otherImages as $upload): ?> <?php if ($upload['hasThumbnail']): ?> <a href="<?php echo $upload['urlPath'] ?>"><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="<?php echo $upload['filename'] ?>" title="<?php echo $upload['info1'] ?>" /></a> <?php endif ?> <?php endforeach ?> <?php if (count($otherImages) > 0): ?> <p id="otherimages-clicklarger">Click on small photos to enlarge</p> <?php endif ?> </td> Here's how it works. First, we load the uploads from the 'other_images' field into $otherImages. Next, we loop over those and for each one that has a thumbnail we display it. Finally, we check the count of 'other_images' and if there is 1 or more uploads we display the "Click on small photos..." text. Let me know how it goes! Dave Edis - Senior Developer interactivetools.com
|
|
|  |
 |

rasbro
User
May 2, 2008, 4:14 PM
Post #10 of 13
(400 views)
Shortcut
|
Phew, that finally did it! Thanks Dave! Hey, what do you think about the other IF/THEN statement issue regarding the display of the "Sorry, No Image" image when main product image not uploaded? Any ideas? Refer to same viewer in the include file I attached earlier. Thanks, Brian
|
|
|  |
 |

Dave
Staff
/ Moderator

May 2, 2008, 4:19 PM
Post #11 of 13
(398 views)
Shortcut
|
|
Re: [rasbro] IF image THEN ...
[In reply to]
|
Can't Post
|
|
Great, glad to hear it's working! For the other it's the same idea:
<td id="sumimg-mainimage"> <?php $mainImages = getUploads($options['tableName'], 'main_image', $record['num']) as $upload); ?> <?php foreach ($mainImages as $upload): ?> <?php if ($upload['hasThumbnail']): ?> <a href="<?php echo $upload['urlPath'] ?>"><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="Product Main Image - <?php echo $upload['filename'] ?>" title="<?php echo $record['name'] ?>" /></a> <?php endif ?> <?php endforeach ?> <?php if (count($mainImages) == 0): ?> <img src="/images/NoImage-main.jpg" alt="NoImage-main.jpg" /> <?php endif ?> </td> Let me know if that does it. Dave Edis - Senior Developer interactivetools.com
|
|
|  |
 |

rasbro
User
May 6, 2008, 12:25 PM
Post #12 of 13
(335 views)
Shortcut
|
Dave, once I discovered this error in the code you gave me... <?php $mainImages = getUploads($options['tableName'], 'main_image', $record['num']) as $upload); ?> and changed it to... <?php $mainImages = getUploads($options['tableName'], 'main_image', $record['num']); ?> then it worked great. Thanks!
|
|
|  |
 |

Dave
Staff
/ Moderator

May 6, 2008, 2:25 PM
Post #13 of 13
(331 views)
Shortcut
|
|
Re: [rasbro] IF image THEN ...
[In reply to]
|
Can't Post
|
|
Ahh yes, good eye. That was my mistake. Glad it's working now! :) Dave Edis - Senior Developer interactivetools.com
|
|
|  |
|