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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.