PHP Else, Elseif Logic Correct? [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am trying to have 3 actions based on an order being 0 percent fulfilled, 100 percent fulfilled or somewhere in the middle.
The tests I have ran so far suggest this is correct but as I could check every possibility I was hoping someone could run their eyes over it and point out any obvious wrong-doings.
//$success & $unsuccess are counts of the good/bad fulfilment items.
$percentfulfilled = round((($success/($success+$unsuccess))*100),2);
//If 0% fulfillled
if($percentfulfilled == '0')
{
}
//If 1-99% fulfilled
elseif($percentfulfilled < '100' && $percentfulfilled > '0')
{
}
//If 100% fulfilled
elseif($percentfulfilled = 100)
{
}

Your last statement is missing an equal
elseif($percentfulfilled == 100)
//^here
In the last stament you were not checking the condition but you were assigning a value to variable.

Related

Php Or operator doesn´works propertly [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 11 months ago.
Improve this question
I´m trying to use or operator in a php sentence but only validate the first condition, what´s wrong?
if ($_SESSION['user_id'] != 4 || $_SESSION['rol'] != 1)
{
//exit
}else{
//do something
}```
You should invert the condition in this way:
if ($_SESSION['user_id'] == 4 || $_SESSION['rol'] == 1)
//it's ok
else
//exit
Because otherwise if the user_id is 4 it will otherwise fail if it doesn't have the role expected

"Division by zero" PHP [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
What could be the cause of this error? I already check it with if/else statement in the first level. How can it still show the "Division by zero" error?
if($sum != 0) {
$percent = (($sum / $tss) * 100);
} else {
$percent = 0;
}
You check $sum. You should be checking $tss.

Why is "00:00:00" seen as being the same thing as NULL in MYSQL Time field? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I have a mysql field called "time_of_birth" that is definitely set to NULL.
I have a PHP check on that field like this:
if ($row['time_of_birth'] !== "00:00:00") {
//do this stuff
} else {
//do something else
}
For that field that is definitely set to NULL, it's doing the "do this stuff". Isn't NULL different than "00:00:00"? I would expect it to do "do something else" because it's not exactly equal to "00:00:00".
What am I missing here?
I think it is doing it correctly. It is not seeing null as equal to '00:00:00' !== is a proof that it is not seeing it as same and entering that block.

Checking userlevel but it won't work [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm not the best at php and mysql and i'm still learning however i have this userlevel variable which i define in my session
and if i message it back to myself using
<?php echo"$session->userlevel"; ?>
It'll work, it'll tell me that me that my userlevel is "0" which it should be however when i'm using an if statement to check it won't work?
<?php
if ($_SESSION['userlevel'] = 0) {
echo "Userlevel 0 was found!";
}
?>
Any though
if($_SESSION['userlevel'] = 0)
should be
if($_SESSION['userlevel'] == 0)
Otherwise you don't check, you assign the value 0 to $_SESSION['userlevel']

PHP "IF conditions" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Example 1)
if(5 == $brandId)
{
}
Example 2)
if($brandId == 5)
{
}
can somebody please explain the difference between this two conditions
In first condition you have 5 compared with value of $brandId, while in second condition you have $brandId value compared with 5.
It's only code style difference, because there is no difference (5 == 5)
They work identically as you can say 5 == 4 + 1 or you can say 4 + 1 == 5. In that respect they are identical as both compute to true (as a boolean).
One reason to use example 1 is if you typo it, like if ($brandId = 5), then the $brandId will be overwritten with the value 5. I don't know any other differences between these two, I tend to use the latter (example 2), because I think its easier to read/understand.

Categories