0
<?php echo $row['time']; ?>&nbsp;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?

3 Answers 3

1
<?php $years = $row['time']/2; ?>
<?php echo $row['time']; ?>&nbsp;Semster (<?php echo $years > 1 ? $years.' years' : $years.' year'; ?>)
Sign up to request clarification or add additional context in comments.

Comments

0

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. :)

Comments

0
<?php echo $row['time']; ?>&nbsp;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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.