Re: Counting down

From: Jerry Stuckle <jstucklex_at_attglobal.net>
Date: Tue, 22 Aug 2017 12:12:38 -0400
Message-ID: <onhksv$ifv$1_at_jstuckle.eternal-september.org>


[Quoted] On 8/20/2017 11:46 PM, bit-naughty_at_hotmail.com wrote:
> I have a DB, say 10 rows, with a primary key, numbered 1 to 10. Now, according to a PHP variable I have, say $i, I would like to fetch the 10th - $i field in the DB, ie. if $i is 3, then I wanna retrieve the 7th field in the DB. (it'll have to be sorted in DESC order, right?)
> How do I word the SQL statement, putting the $i into it? The quoting and stuff confuses me.... :)
>
>
> Thanks.
>

[Quoted] Forget TNP's "answer". It's his normal crap answer and only works if you have exactly 10 rows and the primary keys are 1-10.

[Quoted] What you need is the LIMIT clause, i.e.

SELECT col1, col2, col3 FROM mytable ORDER BY keycol DESC LIMIT 3,1;

Play with the first LIMIT value to get the exact row you want.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex_at_attglobal.net
==================
Received on Tue Aug 22 2017 - 18:12:38 CEST

Original text of this message