Re: Counting down

From: The Natural Philosopher <tnp_at_invalid.invalid>
Date: Mon, 21 Aug 2017 09:02:13 +0100
Message-ID: <one3q4$fk$1_at_dont-email.me>


On 21/08/17 04:46, 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.
>
$query=sprintf("select myfields from mytable where id='%d'",10-$i);

-- 
"The great thing about Glasgow is that if there's a nuclear attack it'll 
look exactly the same afterwards."

Billy Connolly
Received on Mon Aug 21 2017 - 10:02:13 CEST

Original text of this message