[thelist] Fetching rows 5 above and 5 below a target row...

Mark Groen evolt at markgroen.com
Mon Dec 18 08:27:28 CST 2006


On Monday 18 December 2006 02:16, Tris wrote:
> Hi all...
>
> I've been asked to put together a league table thingy for a client.
> What they want is to show the current users position, relative to the
> whole board.
>
> So, If I'm ranked 356 for example, on my leauge table view, I wanna
> see me highlighted inthe middle and Ranks 350 - 355 above me, and then
> 357 - 361 below me.
>
> each user in the DB has a score tally, that increments as the user
> plays the game. (It's a quiz thing).
>
> So eg:
>
> SELECT userName, score FROM resultsTable WHERE userName =
> '$myUserName' (and 5 above/below too!) ORDER BY score DESC LIMIT 11
>
> Is this easy, google is making my Monday morning hard... :-(
>
> Tris...

The Operator you are looking for is BETWEEN, here's a tute:

http://www.webdevelopersnotes.com/tutorials/sql/tutorial_mysql_in_and_between.php3

-- 
cheers,

        mark



More information about the thelist mailing list