php - MySQL selecting "previous" max(id) WHERE -
i have table inserts data when kid checks in summer camp area. if kid < 12 years of age parents barcode must scanned allow kid entry young kids area (<12 years of age).
the table has following columns.
kcid uid id age room barcode date amber
the data presented this.
kcid uid id age room barcode date amber 25 1 1 30 1000 0001 6/26/2014 1:27:40 0 26 6 1 1 1000 0005 6/26/2014 1:27:40 0
the problem have need compare dates/hours know if kid entering or leaving camp area , via php send sms parents know kid outside particular area.
i know can retrieve max(kcid) barcode = xxxx , return last inserted row, but, in order me retrieve said information kid must scanned, inserting new row , rendering max(kcid) useless in case.
what need able select max(kcid) barcode = xxxx , select previous row record in barcode = xxxx found. way can compare dates , know if kid leaving or entering particular area.
the easiest solution can think of right have 2 tables (1 entry 1 out) , have camp counselors choose if kid entering or leaving i'm wondering if can use 1 table.
you add column indicating leave / return, , add condition.
e.g.
alter table `table` add `status` enum('left', 'returned') not null default 'left';
a query be
select `kcid`, `barcode` `table` `status` = 'left' order `timefield` desc limit 1
Comments
Post a Comment