Jump to content

selecting random rows and setting value to each one


Smudly

Recommended Posts

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.

What are you having trouble with figuring out? It certainly sounds like you know what you want to accomplish.

 

I would start out by working through your code in pseudocode. That is,

 

connect to mysql

connect to db

if table not exists

    create table

numrows = number of rows

foreach row in table

    row = random_number()

for i=0;i < numrows;i++

    mysql(select status, credits from table where value = i)

 

. . .

 

then figure out what you need to work on to make it happen

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.