Jump to content

[SOLVED] Simple If statement trouble


TylerDiaz

Recommended Posts

So I've dealt with IF's before on PHP. But never with math operators.

 

So the code that is not working is the following.

 

$message = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent sapien. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris quam ante, pellentesque vel, euismod eu, tempus vel, risus. Aenean nibh. Phasellus cursus mattis erat. Suspendisse venenatis tempus felis. Vivamus sed augue et elit faucibus mollis. In luctus. Aenean faucibus interdum sem. Donec vitae tortor ut neque fermentum pretium. Nulla sem neque, consectetuer sed, euismod in, elementum non, felis. Praesent scelerisque dignissim sapien. Sed et pede. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas venenatis. Fusce adipiscing tincidunt mauris.";

$myid = 1;

$gold_message = strip_tags(trim(strlen($message)));

echo $gold_message;

if ($gold_message < 59){

$this->System->add_gold($myid, 1);

} elseif ($gold_message > 60 || $gold_message <= 109){

$this->System->add_gold($myid, 2);

} elseif ($gold_message >= 110 || $gold_message <= 199){

$this->System->add_gold($myid, 3);

} elseif ($gold_message >= 200 || $gold_message <= 279){

$this->System->add_gold($myid, 4);

} elseif ($gold_message >= 280 || $gold_message <= 339){

$this->System->add_gold($myid, 5);

} elseif ($gold_message >= 340 || $gold_message <= 414){

$this->System->add_gold($myid, 6);

} elseif ($gold_message >= 415 || $gold_message <= 499){

$this->System->add_gold($myid, 7);

} elseif ($gold_message >= 500 || $gold_message <= 574){

$this->System->add_gold($myid, 8);

} elseif ($gold_message >= 575 || $gold_message <= 634){

$this->System->add_gold($myid, 9);

} elseif ($gold_message >= 635 || $gold_message <= 709){

$this->System->add_gold($myid, 10);

} elseif ($gold_message >= 710 || $gold_message <= 779){

$this->System->add_gold($myid, 11);

} elseif ($gold_message >= 780 || $gold_message <= 855){

$this->System->add_gold($myid, 12);

} elseif ($gold_message > 855){

$this->System->add_gold($myid, 14);

}

 

I have tested the System add gold, so pay not attention to that please. ;)

 

See the problem is, as soon as it sees "$gold_message > 60" and its value IS above 60 characters, it stops there and adds nothing but 2 gold when the message value is far longer than 60 characters.

 

Anyway I can fix it, any alternatives? Thanks in advance.

Link to comment
Share on other sites

Instead of using a logical OR (||), you should use AND (&&).

 

Right now you're saying:

If message length is greater than 60 OR less than or equal to 109 Add 2

 

That will always return true if the length is over 60 - thus always executing that code.

Link to comment
Share on other sites

Instead of using a logical OR (||), you should use AND (&&).

 

Right now you're saying:

If message length is greater than 60 OR less than or equal to 109 Add 2

 

That will always return true if the length is over 60 - thus always executing that code.

 

Nothing makes my day more than quick and clear support. Another lesson learned for the day.

 

I appreciate the inhuman quick reply to my humble simple question.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.