4 posts by 2 authors in: Forums > CMS Builder
Last Post: October 30, 2018   (RSS)

By daniel - October 29, 2018

Hi Kenny,

Do you have any other related code that could be outputting icons? An if/elseif chain like in your post should only ever output one result, so having a problem with more than one icon showing up is unexpected.

It also looks like you have your comparisons backwards (> instead of <), meaning that fa-grin-beam will show up after 15 days rather than at 0-15 days. If you switch those operators - and there isn't any other icon code - it looks like it should be doing what you want.

Let me know if you have any more questions!

Thanks,

Daniel
PHP Programmer
interactivetools.com

By KennyH - October 29, 2018

Hi Daniel,

The output with the way the statements are written now shows just a grin-beam (15 Days)

I changed 15 days to < instead of > and a 90+ day entry jumped to 20. So, I switched 20 to < instead of > and it worked. I ran some other tests and it seems to be running good that way.

<?php if (time() - strtotime($record['updatedDate']) < 60*60*24*15): ?>
<i class="fal fa-grin-beam fa-lg text-default"></i>

<?php elseif (time() - strtotime($record['updatedDate']) < 60*60*24*20): ?>
<i class="fal fa-grimace fa-lg text-warning"></i>

<?php elseif (time() - strtotime($record['updatedDate']) > 60*60*24*30): ?>
<i class="fal fa-frown-open fa-lg text-danger"></i>

<?php else : ?>
<i class="fal fa-frown-open fa-lg text-danger"></i>

<?php endif ?>

By daniel - October 30, 2018

Hi Kenny,

Based on the code above, you should get the following results:

  • Between 0-15 days: grin-beam
  • Between 15-20 days: grimace
  • Over 20 days: frown-open

If that's the result you want, you can simplify it a bit further by removing the 30-day "elseif" so it looks something like this:

<?php if (time() - strtotime($record['updatedDate']) < 60*60*24*15): ?>
<i class="fal fa-grin-beam fa-lg text-default"></i>

<?php elseif (time() - strtotime($record['updatedDate']) < 60*60*24*20): ?>
<i class="fal fa-grimace fa-lg text-warning"></i>

<?php else: ?>
<i class="fal fa-frown-open fa-lg text-danger"></i>

<?php endif ?>

Cheers,

Daniel
PHP Programmer
interactivetools.com