Donn Posted December 13, 2006 Share Posted December 13, 2006 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 More sharing options...
The Little Guy Posted December 13, 2006 Share Posted December 13, 2006 $sql = mysql_query("SELECT *, MAX(id) FROM table_name"); Link to comment https://forums.phpfreaks.com/topic/30538-select-last-records/#findComment-140580 Share on other sites More sharing options...
craygo Posted December 13, 2006 Share Posted December 13, 2006 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 More sharing options...
Donn Posted December 13, 2006 Author Share Posted December 13, 2006 Ray thanks for you help, the second one works great, however this shows the last time they where in, If they where to have a status of 'out' after the last staus of 'in' I could do with it not showing.cheers Link to comment https://forums.phpfreaks.com/topic/30538-select-last-records/#findComment-140609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.