BernardoPiedade
BernardoPiedade

Reputation: 27

Compare two values coming from diferent queries

I have a local dashboard where I see data from my software. I have a function which tells me the total of Active Users in real time.

I'm trying to create a function which let's me know the the record of online users, what I want is to get the number of active users, then get the number of the record, compare them and if the number of active users is higher then it would send a query to update the value of the record.

The function is getting all values but it is not updating the record.

This is the function:

function recordUsers($conn)
    {
        $resultAU = mysqli_query($conn, "SELECT * FROM activeUsers");
        $AU_row_cnt = mysqli_num_rows($resultAU);

        $resultRU = mysqli_query($conn, "SELECT * FROM recordUsers");

        $RU_r = mysqli_fetch_assoc($resultRU);

        if($AU_row_cnt > $RU_r)
        {
            mysqli_query($conn, "UPDATE recordUsers SET num = ".$AU_row_cnt."");
        }

        $new_resultRU = mysqli_query($conn, "SELECT * FROM recordUsers");

        $new_RU_r = mysqli_fetch_assoc($new_resultRU);

        return $new_RU_r['num'];
    }

Upvotes: 1

Views: 35

Answers (1)

Nathanael
Nathanael

Reputation: 982

in

if($AU_row_cnt > $RU_r)

$RU_r is an array so the test here would result in an error,

try instead

if($AU_row_cnt > $RU_r['num'])

Upvotes: 2

Related Questions