Skip to main content
August 28, 2007
Question

display random mysql record after every 8 seconds???

  • August 28, 2007
  • 2 replies
  • 336 views
Looking to see if I could get some suggestions on how to achieve the following. I want to display the contents of random mysql records every 8 seconds but I am not sure how to code the every 8 seconds.

Any suggestions?
This topic has been closed for replies.

2 replies

August 28, 2007
Dave,

Thanks for you answer, I am still a newbie regarding coding (under 2 years) so I found your post very informative.
Inspiring
August 28, 2007
cdembek wrote:
> Looking to see if I could get some suggestions on how to achieve the following.
> I want to display the contents of random mysql records every 8 seconds but I am
> not sure how to code the every 8 seconds.

Apart from the fact that running a MySQL query every 8 seconds is likely
to use a lot of resources and probably result in an intensely annoying
web page, you are attempting something for which server-side programming
is not designed. A dynamic page using PHP (or any other server-side
language) is created by sending a request from the browser to the
server, where it queries the database, and sends back the result. So, to
do what you want, you need to send a new request every 8 seconds.

The only way to guarantee that it will work is to send a request for the
full page, using the refresh meta tag. This is extremely wasteful of
resources, and is likely to drive visitors mad, as the page rebuilds
seven times a minute. To rebuild just the part of the page that you want
to change, you would need to use Ajax or Flash.

A more sensible approach might be to send one query to the database, and
store a large number of results in an array. You could then use
JavaScript and DOM manipulation to select an element from the array at
random. However, like Ajax, this approach depends on JavaScript being
enabled in the browser. You would also need considerable scripting
skills to set it up.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/