How to get last inserted date of a certain record using php and mysql?

Viewed 193

Below I have a working code:

$p_code = "R-BIGANTE-010";
$date = date("m/d/Y");
$statement=$pdo->prepare("SELECT * FROM items WHERE p_code=? AND date=?");
$statement->execute(array($p_code, $date));

And what it does is to get a certain item with p_code and date equal to TODAY. What I want to know is how can I query a specific item with the last latest update?

For example, in my items table I have

enter image description here

As you can see, I have two p_code with value "R-BIGANTE-010". Let's say the current date today is 05/06/2017 and I want to get the highlighted one because the date field is much latest than the other value.

How can I query it? By the way the date value is in varchar since the code is old and I will clean everything later.

Any help would be much appreciated.

4 Answers
Related