View Full Version : Javascript + PHP = Count Rows

09-22-2009, 04:09 AM
Hi I am currently working on a project, where I need to count in an ajax/javascript way to show when a new row is added, without the user having to refresh the page.

As we use MySQL, PHP5 and we already use some javascript, I am wondering how I would get it to show a counter like http://www.twitpocalypse.com/
But instead of all being Javascript, it would count how many rows are in the DB.

The table that we want to get the data out of is named entry

09-23-2009, 12:51 AM
Ajax is just a method to get data from PHP. Simply put, you need to just design a script in php that will return the number of rows, request that with Ajax, and display that value in Javascript. It shouldn't be too difficult if you've already got most of it setup, but you will need to worry about security issues (because Ajax requests are made the same way anyone could request that PHP script, so be sure it doesn't reveal anything you don't want to be public knowledge).