Reputation: 37
<?php echo $row['time']; ?> Normal time (<?php echo $row['time']/2; ?> years)
I want to have a case when ['time']/2 > 1 it is shown as years but if it is 1 it shall be shown only as year
How can I do this using if else
any idea?
Upvotes: 0
Views: 60
Reputation: 2376
You only want to show "year" if $row['time']/2 is 1 (0 is still plural), so you want to do something like:
<? $years = $row['time'] / 2; ?>
<?= $row['time'] ?> Semester (<?= $years == 1 ? '1 year' : $years.' years' ?>)
Good luck. :)
Upvotes: 0
Reputation: 30170
<?php echo $row['time']; ?> Semster (<?php echo $row['time']/2; ?> year<?php if( $row['time']/2 > 1 ): ?>s<?php endif; ?>)
Leave off the s
and only add it if time/2 > 1
Upvotes: 0
Reputation: 3550
<?php $years = $row['time']/2; ?>
<?php echo $row['time']; ?> Semster (<?php echo $years > 1 ? $years.' years' : $years.' year'; ?>)
Upvotes: 1