Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi,
I have a column containing dates (date datatype)
now a user can select a date via php or whatever,
the result the user has to get is the data stored for the previous date
for example:date1 x1 y1 z1
date2 x2 y2 z2
date3 x3 y3 z3now if the user selects date2 the result should be x1,y1,z1
if the user selects date3 the result should be x2,y2,z2the dates are completely random, so I need a query that will look for the date previous to the one selected without using any further data from the table!
how would I accomplish this?
thx :)edit:
dates are also randomly added, so indexing them is of no use since the order of the indexes will not match that of the dates

you can do the following in mysql.
select year(date2) - 1,month(date2)-1,day(date2)-1
from Sometable.This will return the values of the dates from the preceding date.
This could work if all the dates are incremented by 1 for each value.

thx for your input, but dates are not incremented by 1 for each value, like I said, they're completely random...
let me give you a clearer example:2009-02-05 x1 y1 z1
2009-04-18 x2 y2 z2
2009-06-06 x3 y3 z3so if the user selects 2009-06-06, the data from the previous date has t be returned, in this case x2,y2,z2
so here your solution will not work, and it's goind to be like this in most cases, if not all cases...I guess I could just query all dates meeting certain criteria, order them, and then in php for example put them in an array and use a for-loop to get the info, but that seems bloated to me
+ after a while these queries are going to give a lot of rows so I don't want to have to load them all into my front code...

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |