selecting random rows and setting value to each one

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smudly
Forum Commoner
Posts: 71
Joined: Wed Jun 09, 2010 10:09 pm

selecting random rows and setting value to each one

Post 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.
Kurby
Forum Commoner
Posts: 63
Joined: Tue Feb 23, 2010 10:51 am

Re: selecting random rows and setting value to each one

Post 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
Post Reply