Jump to content

Total hours to Next Rank - Code request


djtiger76

Recommended Posts

Hi all.
I have a section on the front page of my crew center that gives a snapshot of how many hours are left before the pilot reaches the next rank.
The problem... When the pilot maxes out it starts to give a negative number. 

mrVI1w.jpg

 

I would like to add an "if" statement to the following code that says basically, if the hours = < 0, then display "Congratulations<br>You have reached the highest rank."

 

<div class="small-box bg-blue">
                <div class="inner">
                    <h3><?php echo ($nextrank->minhours - $pilot_hours)?> Hours</h3>

                    <p>until promotion to<br>
                    <?php echo $nextrank->rank?>!</p>
                </div>
                <div class="icon">
                    <i class="ion ion-checkmark"></i>
                </div>
            </div>

Link to comment
Share on other sites

Try this:

<div class="small-box bg-blue">
    <div class="inner">
        <?php
        $hours = ($nextrank->minhours - $pilot_hours);
        if ($hours < 0) {
            echo '<h3>Congratulations <br> You have reached the highest rank.</h3>';
        } else {
            echo '<h3>'.$hours.' Hours</h3>';
            echo '<p>until promotion to <br> '.$nextrank->rank.'!</p>';
        ?>
    </div>
    <div class="icon">
        <i class="ion ion-checkmark"></i>
    </div>
</div>

 

Link to comment
Share on other sites

Oops forgot to close the bracket

Try this:

<div class="small-box bg-blue">
    <div class="inner">
        <?php
        $hours = ($nextrank->minhours - $pilot_hours);
        if ($hours < 0) {
            echo '<h3>Congratulations <br> You have reached the highest rank.</h3>';
        } else {
            echo '<h3>'.$hours.' Hours</h3>';
            echo '<p>until promotion to <br> '.$nextrank->rank.'!</p>';
	}
        ?>
    </div>
    <div class="icon">
        <i class="ion ion-checkmark"></i>
    </div>
</div>

 

Edited by web541
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...