Jump to content

Random Numbers From Mysql Database?


agnarkb
 Share

Recommended Posts

What do you mean by "random numbers from a MySQL database"? Are you just trying to generate random numbers? You don't need a database for that. Are you trying to select random records from a certain table?
Lets say I have SQL table that includes 20 numbers. I want to make them appear on a PHP website randomly with intervals.
Link to comment
Share on other sites

OK, so you want to select a random record from the table. You can do that like this:SELECT * FROM table ORDER BY RAND() LIMIT 1If you want things to happen on an interval, you can either use a meta refresh tag to refresh the entire page after a few seconds, or you can use the Javascript setTimeout or setInterval functions to run a piece of Javascript code after a certain amount of time. You would use Javascript to send an AJAX request to PHP to get the next number.

Link to comment
Share on other sites

OK, so you want to select a random record from the table. You can do that like this:SELECT * FROM table ORDER BY RAND() LIMIT 1If you want things to happen on an interval, you can either use a meta refresh tag to refresh the entire page after a few seconds, or you can use the Javascript setTimeout or setInterval functions to run a piece of Javascript code after a certain amount of time. You would use Javascript to send an AJAX request to PHP to get the next number.
Code examples?
Link to comment
Share on other sites

There are plenty online, the difference between setTimeout and setInterval is that setTimeout will run the code once, and setInterval will keep firing until you specifically stop it. Do a search for either of those to find examples.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...