Re: Random record from latest 10 entries...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In message <167682.50491.qm@xxxxxxxxxxxxxxxxxxxxxxx>, Anees
<anees_muhd@xxxxxxxxx> writes
>HI
>
>I need to show a random image from Data base, 
>and it should be from the latest 10 records
>
>How can i get it by executing only ONE query?
>Please help me
>

You would need an autoincrementing ID field, call it imageID, then
SELECT image FROM tablename WHERE lnkID=(SELECT(ROUND(MAX(
imageID)-RAND()*10)) FROM tablename );

It will need tweaking, but it should humour your tutor...

-- 
Pete Clark

Sunny Andalucia
http://hotcosta.com/Andalucia.Spain

[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux