Q:

Making if conditions using query results in PHP

Hey my knowledge about php is still poor how ever I've tried to solve that myself whole night with no sucess:
<?php
$connect = mysqli_connect("xxxx", "xxxx", "xxxx", "xxxx");
$query = " SELECT AVG(`humidity`) 
           FROM `ESP8622TEST` 
           WHERE `logdatetime` > DATE_ADD(NOW(), INTERVAL -2 HOUR)";
    $result = mysqli_query($connect, $query);
    while ($row = mysqli_fetch_array($result, MYSQL_NUM)) {
        printf ("humidity: %s ", $row[0] );  
    }

    if ($row[0] <= '30'){
        $connect = mysqli_connect("xxxx", "xxxx", "xxxx", "xxxx");
        $querycase = "UPDATE PODLEWDLUGO 
                      SET podlewanieonoff='1' ,jakdlugo='8' 
                      WHERE id=1 ";
        mysqli_query($connect, $querycase);
    };
    if ($row[0] <= '35' && $row[0] >='30'){
        $connect = mysqli_connect("xxxx", "xxxx", "xxxxx", "xxxx");
        $querycase = "UPDATE PODLEWDLUGO 
                      SET podlewanieonoff='1' ,jakdlugo='7'
                      WHERE id=1 ";
        mysqli_query($connect, $querycase);
    };
?>

it seems $row[0] == 0 coz it always UPDATE table with 8 but printf works fine so my qestion is did i miss any synax or shud use something else than mysqli_fetch_array any help appriciated and sorry for my bad english :)

A:

Use mysqli_fetch_row instead of mysqli_fetch_array in your while loop.
The documentation is here http://php.net/manual/en/mysqli-result.fetch-row.php
Also, your if statements are outside the while loop. I think that $row[0] refers to the last row of your returned rows if not null.
Let me know if that solved your problem

