Grow your CSS skills. Land your dream job.

if else statement help

  • # April 17, 2013 at 7:05 am

    Hi, Im new to php so I’m having a small problem with if statments

    basically I want an out put to be if its less that 18 to show less than 18 message, if its more than 23 then show its more than 23 message and if its a range between 18 and 23 to say a mid range message. I can get it to output corectly for more than 23 and less than 18 but I cant get it to output for anything between 18 and 23.

    can any one help please

    (http://codepen.io/anon/pen/qdKyp “code on codepen”)http://codepen.io/anon/pen/qdKyp[code is here](http://codepen.io/anon/pen/qdKyp “code on codepen”)http://codepen.io/anon/pen/qdKyp

    # April 17, 2013 at 7:22 am

    if ($result < 18) {
    // less than 18
    } elseif ($result > 23) {
    // more than 23
    } else {
    // between 18 and 23
    }

    # April 17, 2013 at 7:33 am

    when i change the last elseif to else the page dosent display

    # April 17, 2013 at 7:38 am

    You have

    < ?php if($resultB < 18 or $resultB > 23 or $resultB = range(18,23)): ?>

    < ?php if($resultB < 18): ?>

    < ?php elseif($resultB > 23): ?>

    < ?php elseif($resultB = range(18,23)): ?>

    < ?php endif; ?>

    < ?php endif; ?>

    if you change the last elseif to `< ?php else: ?>` it doesn’t work?

    # April 17, 2013 at 7:39 am

    You might as well remove the outer if by the way, it does nothing.

    # April 17, 2013 at 7:48 am

    < ?php if($resultB < 18 or $resultB > 23 or $resultB = range(18,23)): ?>

    Wellbeing

    < ?php if($resultB < 18): ?>

    < ?php elseif($resultB > 23): ?>

    < ?php elseif($resultB = range(18,23)): ?>


    < ?php endif; ?>
    < ?php endif; ?>

    yep thats what I have and I changed to:

    < ?php if($resultB < 18 or $resultB > 23 or $resultB = range(18,23)): ?>

    Wellbeing

    < ?php if($resultB < 18): ?>

    < ?php elseif($resultB > 23): ?>

    < ?php else($resultB = range(18,23)): ?>


    < ?php endif; ?>
    < ?php endif; ?>

    # April 17, 2013 at 7:48 am

    if change to else then page does not load.

    # April 17, 2013 at 7:49 am

    < ?php else($resultB = range(18,23)): ?>

    should be

    < ?php else: ?>

    # April 17, 2013 at 8:28 am

    All working now, thank you for your help :) learned alot there…. also removed outer if statement cheers

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".