Page 1 of 1

selecting random rows and setting value to each one

Posted: Mon Jun 14, 2010 12:56 pm
by Smudly
Hi,

I am attempting to create a script that will give each row inside my database (each one contains a website url) a random value from 1 to the total number of rows in the table. Once each one is set, my script will go to the row with the value that has been set to 1. If that row's active status is == to Yes, and it's Credits > 0, the website will be selected to be shown to the user. If not, it will skip that row, and do the same checks for Row 2.

I'm having difficulty figuring this out.

Re: selecting random rows and setting value to each one

Posted: Mon Jun 14, 2010 1:02 pm
by Kurby
I think you just need a mysql query that selects a row that has credits > 0 and status = yes?

SELECT * FROM table
WHERE credits > 0
AND status = 'yes'
ORDER BY RAND()
LIMIT 1