0

So currently I am trying to get the lowest time from a column in mysql (the time is an int) to make a queue system if you can call it that.

However I was struck with a problem that lead me back here. The problem arises when instead of the lowest time value, I get the lowest type value (also an INT)

currently I use php mysqli_fetch_array() to get an array from the result so I can then use php min()

if (isset($_GET['type'])) {
    $stmt = $conn->prepare('SELECT * FROM render_queue WHERE type=?');
    $stmt->bind_param('i', $_GET['type']);
    $stmt->execute();
    $result=$stmt->get_result();
    $row= mysqli_fetch_array($result);
    echo min($row['date_submit']);
    exit();
}

The exit is there so I can see what gets returned.

This should be outputting the lowest time from the database but instead outputs the lowest type from the row. Any help I can get is greatly appreciated!

1 Answers1

0

You need to do ORDER BY date_submit ASC LIMIT 1

if (isset($_GET['type'])) {
    $stmt = $conn->prepare('SELECT * FROM render_queue WHERE type=? ORDER BY  date_submit ASC LIMIT 1');
    $stmt->bind_param('i', $_GET['type']);
    $stmt->execute();
    $result=$stmt->get_result();
    $row= mysqli_fetch_assoc($result);
    echo $row['date_submit'];
    exit();
}
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98