PHP Array from MySQL

I have formed a MySQL query that works ok from phpmyadmin SQl query

I have written some php to perform the same query.

The query works but I cannot extract and manipulate the result.

$query = “SELECT MAX(speed) FROM positions where DATE(devicetime) = CURDATE()”;

I get back an array of length 1. I cannot get the value from it at all.

The “print_r” shows the following:
(
[MAX(speed)] => 32
)

I want to get the value 32.

An extract of the code is below.

$query = “SELECT MAX(speed) FROM positions where DATE(devicetime) = CURDATE()”;

$result= mysqli_query($opendb,$query) or die("Query failed " ) ;
$row = mysqli_fetch_assoc($result);
print_r($row);

Add an alias name in the query for the MAX(…) term so that you can reference the data by the alias name.

Without the alias, you would need to use $row['MAX(speed)']

1 Like

many thanks, it was the quotes ’ that solved it. I had tried everything else but that did the trick

Sponsor our Newsletter | Privacy Policy | Terms of Service