Jump to content

[SOLVED] SORT by DESC... but display in reverse?


jewofcanada

Recommended Posts

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.

 

 

 

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.