|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Fetching records in a cyclic order
Hello everybody,
I have 100 records in a table and I would like to show 1 to 40 today and 41 to 80 tomorrow and 81 to 20 the next day.so, something like in cyclic process. How should i write my sql query?? Many thanks |
|
#2
|
|||
|
|||
|
RE: Fetching records in a cyclic order
try using the LIMIT statement in your SELECT query.
you can find an explanation of LIMIT here: http://www.scriptygoddess.com/archives/003313.php Scroll down the page a little and you will find the explaination. |
|
#3
|
|||
|
|||
|
RE: Fetching records in a cyclic order
Blindeddie,
Thats what i was not looking for.well, i can just only limit the records.My question was something different.40 records today and the next 40 tomorrow and it continues like wise. Thanks anyways. |
|
#4
|
|||
|
|||
|
RE: Fetching records in a cyclic order
on day 1 the query would be
select * from mytable limit 0, 40 on day 2... select * from mytable limit 40,40 on day 3 select * from my table limit 80, 20.. based on your post, this is what you want to do is it not? the first number in the limit statement determines what record the displayed records starts at. |
|
#5
|
|||
|
|||
|
RE: Fetching records in a cyclic order
Blindeddie,
Exactly!you got it.Thats what i want to do actually.I dont think thats gonna work with my script, cuz before i display the records i limit the no.of reocrds to display on the page is 10.Thats how i did with the pagination.I've no clue how shld i proceed further. Thanks for your time |
|
#6
|
|||
|
|||
|
RE: Fetching records in a cyclic order
I see what you are saying. Not quite sure how to handle that unless you can add an indicator to the table that flags groups of 40 records and then on a specific day select the records you want for example:
(this will only work if your table is static) add a column to your table called 'day_to_display'. Use a number to indicate that the record should be displayed on a specific day. Day1 = 1, Day2=2 etc... then assign those numbers to banks of 40 records in the table. Then in your select query you could specify which group you wanted to display. since ther will only be 40 records selected, yuo can use the limit statement to do the paging. Like I said, this will only work if the table is static. |
|
#7
|
|||
|
|||
|
RE: Fetching records in a cyclic order
Blindeddie,
I found the solution for this one.First, i got the weekday with this piece of code and then i used switch statement to get the records based on the day, something like: [highlight=php] switch($day) { case "Monday": $query="select * from mytable limit 40"; break; case "Tuesday": $query="select * from mytable limit 40,40"; break; and so on... } so simple aint it?? cheers |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Fetching records in a cyclic order |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|