Posts: 108
Joined: Sun Mar 31, 2013 1:36 pm
Location: Crawley, UK

PHP MySQL query, query.

Sun Jan 13, 2019 4:28 pm

Trying to create an SQL query in PHP.

Neither of these (commented/uncommented) work.
I'm sure it's something simple.....

Code: Select all

require 'connect.php';
$maxtemp_query  = mysql_query("SELECT MAX('temp') AS max_temp FROM 'readings'");
echo mysql_result($maxtemp_query);

// mysqli_query($db, $query) or die('Error querying database.');
// $row = mysqli_fetch_array($query);
// echo $row["max_temp"];


User avatar
Posts: 34557
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: PHP MySQL query, query.

Sun Jan 13, 2019 5:47 pm

Code: Select all

$sql_stmt = "SELECT MAX('temp') AS max_temp FROM 'readings';";
$select_query = sprintf($sql_stmt);

if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
$result = mysqli_query($con, $select_query);
$maxVal = array();
$maxVal = mysqli_fetch_all($result);
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

Return to “Troubleshooting”