Jump to content

Random Numbers From Mysql Database?


agnarkb

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

Archived

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

×
×
  • Create New...