Jump to content

Select last records


Donn

Recommended Posts

Hi

I have a table of 4 fields, field 2 is a field that will have more than 1 entry being the same i.e there may be 50 passcodes of which will all be enetered more than once in a day. Field 3 is a datetime stamp and field 4 is a staus i.e. in / out


  id
  Passcode
  Date 
  status
 
How would I find the last record of the passcode entered and return the last fields value.

to give an example I would like to now all the passcodes that have a current status of In.

any help much appreciated.

Donn
Link to comment
https://forums.phpfreaks.com/topic/30538-select-last-records/
Share on other sites

You are talking about 2 different queries. I imagine id is an auto increment field.

Last row would be like this
[code]<?php
$sql = "SELECT * FROM table ORDER BY id DESC LIMIT 1";
$res = mysql_query($sql) or die (mysql_error());
$r = mysql_fetch_assoc($res);
print_r($r);
?>[/code]

For the status part
[code]<?php
$sql = "SELECT * FROM tabke WHERE status = 'In' ORDER BY id DESC";
$res = mysql_query($sql) or die (mysql_error());
$r = mysql_fetch_assoc($res);
print_r($r);
?>[/code]

Ray
Link to comment
https://forums.phpfreaks.com/topic/30538-select-last-records/#findComment-140590
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.