Ajax, getting Data from the Database every 5 seconds


#1

Hi,

I want to show 3 products every 5 seconds using AJAX. I want to get 3
random products from the database and show them. How would I go about
doing that?

Thanks

David


#2

Use a periodic updater - you can find the documentation under
PrototypeHelper at api.rubyonrails.org.

Then, just generate a random number, use it to find a product, and
return an html fragment that displays it. Not too hard.


#3

Use the following to select a random record from the database in MySQL:

@products = find_by_sql(“SELECT * FROM products ORDER BY RAND() LIMIT
3”);

That should be the one liner you need.

Bryan D. wrote:

Use a periodic updater - you can find the documentation under
PrototypeHelper at api.rubyonrails.org.

Then, just generate a random number, use it to find a product, and
return an html fragment that displays it. Not too hard.