Fall-back image puzzler....?
2 posts by 2 authors in: Forums > CMS Builder
Last Post: September 10, 2012 (RSS)
Hello, All -
Every time someone posts a record on the site they have the option of selecting a themed icon. They get to choose from one of a number of entries on a list - which might denote News, Article, Review, etc.
If they don't choose an icon, the system is designed to use the icon associated with category to which the record has been added.
It all works fine. The only problem is if (for some reason) no one has added a category icon. In which case there is no fall-back option and an rror is generated.
This is the code I'm using:
<?php if ($record['icon']): ?>
<?php $recordTheme = mysql_get('icon_list', $record['icon']); $recordThemeIcon = getUploadRecords('icon_list', 'icon', $recordTheme['num']); ?>
<?php $recordIcon = $recordThemeIcon[0] ?>
<?php else: ?>
<?php $recordThemeIcon = getUploadRecords('category', 'icon', $record['category']); ?>
<?php $recordIcon = $recordThemeIcon[0] ?>
<?php endif ?>
What I would like to do is to change the else statement into an elseif statement and then test to see if the category icon has been uploaded. If no icon is present then the code would fall-back to a default icon.
:0/
Perch
Every time someone posts a record on the site they have the option of selecting a themed icon. They get to choose from one of a number of entries on a list - which might denote News, Article, Review, etc.
If they don't choose an icon, the system is designed to use the icon associated with category to which the record has been added.
It all works fine. The only problem is if (for some reason) no one has added a category icon. In which case there is no fall-back option and an rror is generated.
This is the code I'm using:
<?php if ($record['icon']): ?>
<?php $recordTheme = mysql_get('icon_list', $record['icon']); $recordThemeIcon = getUploadRecords('icon_list', 'icon', $recordTheme['num']); ?>
<?php $recordIcon = $recordThemeIcon[0] ?>
<?php else: ?>
<?php $recordThemeIcon = getUploadRecords('category', 'icon', $record['category']); ?>
<?php $recordIcon = $recordThemeIcon[0] ?>
<?php endif ?>
What I would like to do is to change the else statement into an elseif statement and then test to see if the category icon has been uploaded. If no icon is present then the code would fall-back to a default icon.
:0/
Perch
Re: [Perchpole] Fall-back image puzzler....?
By Jason - September 10, 2012
Hi Perch,
You could try putting in a nested If statement like this:
Hope this helps
You could try putting in a nested If statement like this:
<?php if ($record['icon']): ?>
<?php $recordTheme = mysql_get('icon_list', $record['icon']); $recordThemeIcon = getUploadRecords('icon_list', 'icon', $recordTheme['num']); ?>
<?php $recordIcon = $recordThemeIcon[0] ?>
<?php else: ?>
<?php $recordThemeIcon = getUploadRecords('category', 'icon', $record['category']); ?>
<?php if($recordIcon = @$recordThemeIcon[0]): ?>
// output $recordIcon from category
<?php else: ?>
// output fall back icon
<?php endif ?>
<?php endif ?>
Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/