send javascript timestamp to php function for calculation -



send javascript timestamp to php function for calculation -

i have page i'm trying loop through results mysql query , in block need send js new date().gettime() value php function calculation of time elapsed, within while loop.

how accomplish this?

my php page :

<body> <?php while($rows = $result->fetch_assoc()){ echo "<div>".// here want send time value js function time($a js value)."</div>" } ?> </body>

edit maybe have confused people trying figure out execution time not case. want time value mysql query compared client machine's time js in php function. php function calculates time elapsed.

uh.. strange... of course of study if think important...

it not work if think can js-time client while php script still running code!

but can info via ajax if want.

here go: add together time value sql query dom object of rendered website simple adding javascript var straight (you utilize hidden or visible dom objects of selection long read right objects value javascript)

to ease things (for me) i'm assuming jquery implemented.

javascript header

var sqltime = 1360599506; // unix timestamp set php // let's info user incl timezone var tnow = new date(); // string like: "mon feb 11 2013 17:24:06 gmt+0100" // , timestamp-like number tnow var tstmp = var = math.round(tnow.gettime() / 1000) //and send 3 values via ajax server: var postdata = {action: 'ajaxtime', ts: sqltime, tj: tstmp, tr: tnow}; $.ajax({ type: 'post', url: "http://example.com/my.php", data: postdata, success: function (response) { //do response if want. decode received json string if } }); //you compare 2 timestamps on clientside if more convenient.

and php should have trigger ajax request set php, far possible (but before gets echoed or queried sql!!)

if (array_key_exists('ajaxtime', $_request)) { $sql time = $_post['ts']; $js_timestamp = $_post['tj']; $readable_js_time = $_post['tr']; // here can calculate timestamps , timezone readable_js_time , whatever need to. $json['success'] = true; $json['result'] = "my result calculation"; // create sure no other code of php executed because of ajaxtime request die(); //if want response json string parse in javascript response utilize this: //die (jsonencode($json)); }

php javascript mysql

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -