-1

I'm using laravel if that could be the issue (I'm in the controller) So I have this code.

If my $pool->status is etc OFFLINE it sets it to ONLINE. why is this happening?

foreach($pools as $pool){
        if ($pool->status = 'ONLINE') {
            $pool->cstatus = '
            <i class="zmdi zmdi-shield-check zmdi-hc-lg text-success" data-toggle="tooltip" data-placement="right" title="" data-original-title="OK"></i>
            ';
        }
        else {
            $pool->cstatus = '
            <i class="zmdi zmdi-help zmdi-hc-lg text-muted" data-placement="right" title="" data-original-title="Status unknown."></i>
            ';
        }
    }
joveice
  • 113
  • 2
  • 11

3 Answers3

1

There is difference in "=" and "==" operators. = is assingment operator while == is comparison operator.

Change

  if ($pool->status = 'ONLINE') {

To

 if ($pool->status == 'ONLINE') {
VK321
  • 5,768
  • 3
  • 44
  • 47
1

You used assignemnt operator =, not a comparsion operator.

So:

if ($pool->status == 'ONLINE') {}

Not:

if ($pool->status = 'ONLINE') {}

You can go with yoda condition:

if ('ONLINE' == $pool->status) {}

Because that would throw an error when you mistake operators.

These mistakes are hard to debug, especially for not experienced programmers.

Mateusz Sip
  • 1,280
  • 1
  • 11
  • 11
0

You are using assignment operator in your if statement, instead of conditional equals operator. It is the different between using = and ==

foreach($pools as $pool){
        if ($pool->status == 'ONLINE') {
            $pool->cstatus = '
            <i class="zmdi zmdi-shield-check zmdi-hc-lg text-success" data-toggle="tooltip" data-placement="right" title="" data-original-title="OK"></i>
            ';
        }
        else {
            $pool->cstatus = '
            <i class="zmdi zmdi-help zmdi-hc-lg text-muted" data-placement="right" title="" data-original-title="Status unknown."></i>
            ';
        }
    }
ayip
  • 2,473
  • 1
  • 19
  • 30