php, javascript and mysql live data problem

bportal

New Member
I'm very new to web programming, but I have some data that I would really like to present in a constantly updated time series graph on my website.So I have been trying to prototype some code that will display the latest integer value that has been added to a database.The database table I want to reference is being constantly inserted with integer values.My question is this; I'm trying to use a combination of JavaScript and php to display the latest entry into the database when a button on the website is pressed.However the only integer I can get back is the last integer that was present in the database when the page originally loaded. It appears the php function I am using to grab data from the database is run as soon as the page is loaded and does not update after each button press. Is this a limitation of php (or my knowledge of php). Any help would be much appreciated.(the php function)\[code\]function getData()\[/code\]{ include "config.php";\[code\] $db = mysql_connect($dbhost,$uname,$pass); mysql_select_db ($dbname) or die ("Cannot connect"); $query = "SELECT numCalls FROM $tname ORDER by claatime DESC LIMIT 1"; $result = mysql_query($query); while($r=mysql_fetch_array($result)) { $numCalls = $r["numCalls"]; } return $numCalls;\[/code\]}(javascript function)\[code\] function getNum() { var x = <?php echo getData()?>; alert('the latest number is ' +x); }\[/code\]
 
Back
Top