agnarkb Posted April 22, 2009 Share Posted April 22, 2009 What would be the best way to get random numbers from a MySql database to appear with intervals?Also is there a simple way to make random numbers from a MySql db appear in a table. One number in each <td>? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 22, 2009 Share Posted April 22, 2009 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? Link to comment Share on other sites More sharing options...
agnarkb Posted April 22, 2009 Author Share Posted April 22, 2009 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 More sharing options...
justsomeguy Posted April 22, 2009 Share Posted April 22, 2009 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 More sharing options...
agnarkb Posted April 22, 2009 Author Share Posted April 22, 2009 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 More sharing options...
justsomeguy Posted April 22, 2009 Share Posted April 22, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.