-5

I have MySQL database in LAMP server, Database is called coe and table is called pulses. the columns are:

Pulse | int

id | int

time | timestamp - current timestamp

I want select all values in pulse and then choose the max value with last 1 minute from current time. After that, I want to delete all rows in table with also last 1 minute.

I tried this code:

<?php 

$servername = "localhost"; 
$username = "root";  
$password = "";
$dbname = "testdb";

$mysqli = mysqli_connect ($servername, $username, $password, $dbname);
$res = mysqli_query($mysqli, "SELECT MAX(pulse) as pulse FROM pulses where pulse BETWEEN 400 and 500 AND time > UNIX_TIMESTAMP() - 60");
$row = mysqli_fetch_assoc($res);
echo $row['pulse'];
$DeleteQuery = mysql_query('DELETE FROM pulses WHERE time > (UNIX_TIMESTAMP() - 60)');
?>

The code section of connection with database and select data with max value that work and it is not deleting the rows. i tried a lot but without success. please help

1 Answers1

2

You have mysql_query instead of mysqli_query, check syntax. Like Barry Thomas said, change your > operator to <

  • 2
    He is also using the incorrect operator in the query, he has > should be <. If you wan to update your answer to include. – Barry Thomas Jan 25 '17 at 14:36
  • Thanks i changed into `mysqli_query` and the operator to `<` but also does not work the error is now `mysqli_query() expects at least 2 parameters` on line `DELETE FROM pulses WHERE time < (UNIX_TIMESTAMP() - 60` – Istabraq Mahmood Jan 25 '17 at 14:40
  • add ($mysqli, before "Delete... See the first query –  Jan 25 '17 at 14:44