php - How to select previous record not depends on ID which is AutoIncrements in MySQL? -
php - How to select previous record not depends on ID which is AutoIncrements in MySQL? -
say, have table named tbl_order
on mysql construction (just illustration):
then did next query:
select * `tbl_order` `tbl_order`.`grade` = 'aaa' , `tbl_order`.`order_confim_time` < now() order `tbl_order`.`status` desc, `tbl_order`.`order_confim_time` asc
so in next result:
--------------------------------------------------------------------------------------------------------- | id | grade | type | order_date | order_confim_time | vol_in | vol_out | vol_dev | status | | ai | varch | varch | timestamp | timestamp | double | double | double | varch | --------------------------------------------------------------------------------------------------------- | 91 | aaa | out | 2014-09-12 09:06:00 | null | 0 | 130000 | -2000 | notconf | | 93 | aaa | out | 2014-09-13 10:05:00 | 2014-09-12 14:00:00 | 0 | 115000 | -5000 | confirm | | 89 | aaa | out | 2014-09-12 09:04:00 | 2014-09-12 13:00:00 | 0 | 120000 | -5000 | confirm | | 87 | aaa | out | 2014-09-11 10:03:00 | 2014-09-11 14:00:00 | 0 | 145000 | -5000 | confirm | | 85 | aaa | out | 2014-09-11 09:02:00 | 2014-09-11 13:00:00 | 0 | 99000 | -1000 | confirm | | 83 | aaa | in | 2014-09-10 10:01:00 | 2014-09-10 14:00:00 | 998000 | 0 | -2000 | confirm | | 81 | aaa | in | 2014-09-10 09:00:00 | 2014-09-10 13:00:00 | 498000 | 0 | -2000 | confirm | ---------------------------------------------------------------------------------------------------------i did write next function in model order
in order previous row using recursive:
the result quite , respects order_confirm_time
not null
values.
current result in cgridview
the expected status this
how can previous row without need depends on order id desc
? depends on order order_confirm_time
.
i using yii 1.1.16-branch, php 5.4 @ windows 7 x64, mariadb 5.5.38
in pseudo code, can this:
initialize tempv_var initialize my_array loop records do conditions here before passing records my_array stored records in my_array[temp_var] increment temp_varat end have my_array contents records index of temp_var. straight forwards solutions, can within sql query , adding logic on script.
php mysql sql yii
Comments
Post a Comment