jewofcanada Posted September 28, 2008 Share Posted September 28, 2008 What I'm trying to do is create a mini-schedule on my website. It has a list of 7 games. The first 3 are recent games, the next 4 are upcoming games. They're two different queries, so all we need to worry about are the top 3, the recent games. The easiest way to explain this as follows. Let's say I have 7 games in the schedule: 1 2 3 -- ^^ these three have been played... the next 4 are upcoming 4 5 6 7 So then the date passes for game 4, the table should look like this: 2 3 4 -- ^^ these three have been played... the next 4 are upcoming 5 6 7 8 if I use ORDER BY ASC LIMIT 3, it will ALWAYS just show the 1 - 2 - 3... if I use ORDER BY DESC, it will display the 3 games that i want (3-2-1, or 4-3-2, 5-4-3, etc), but in reverse order. How can I make it display 1-2-3, then 2-3-4, 3-4-5, etc. Quote Link to comment Share on other sites More sharing options...
jewofcanada Posted September 29, 2008 Author Share Posted September 29, 2008 After some research I found a method of doing it... for those interested: //count how many games have passed $total_gp=mysql_query("SELECT * FROM calendar WHERE ev_dat<='$today' ORDER BY ev_dat ASC"); $total_gp=mysql_num_rows($total_gp); //set the start point... because I want to display 3, i subtract 3 from the total $start_point=($total_gp - 3); // using LIMIT x,y -- set x to $start_point, y to 3 and viola. $sql=mysql_query("SELECT * FROM calendar WHERE ev_dat<='$today' ORDER BY ev_dat ASC LIMIT $start_point,3"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.