Page 1 of 1

saving to database after few seconds questions

Posted: Thu Oct 23, 2008 8:20 am
by iory
dear all, im newbie here :p
I have this code, after user make a selection, he/she see the data that he/she selected,
then, that data name will be automatically save into their record database. is it possible
to make that, the record will be saved after user see for few seconds (ex: 5 seconds).
so that it wont save immediately ( for consideration that, if user see the data for more than 5 seconds, that
means he/she is interested, then it should be saved automatically)

here is the code:

Code: Select all

 
if ($registration>0){
$qry="SELECT * FROM registration WHERE id_registration=".$registration" LIMIT 1";
$exe=mysql_query($qry);
$show=mysql_fetch_array($exe);
if (mysql_num_rows($exe)==1){
echo "<div class='divide'>&nbsp;&nbsp;++ ".$show['title_registration']." ++</div><br />";
 
$query="INSERT INTO record_table VALUES('',".$_SESSION['ID'].",
'http://".$_SERVER[HTTP_HOST]."".$_SERVER[REQUEST_URI]."',
'".date("Y-n-j H:i:s")."')";
 
can someone please help me with this? :(

Re: saving to database after few seconds questions

Posted: Thu Oct 23, 2008 9:03 am
by VladSun
The easiest way is to have a hidden IFRAME with a refresh period of 5 sec and reloading to your save-to-db URL.

Re: saving to database after few seconds questions

Posted: Thu Oct 23, 2008 9:09 am
by iory
Is that possible? for the current code, right after user see the data,
the "data name" will save automatically into the database. so, i think even if im using IFRAME , before it reloads, it will already save the "data name" automatically :(

Re: saving to database after few seconds questions

Posted: Thu Oct 23, 2008 9:11 am
by VladSun
iory wrote:so, i think even if im using IFRAME , before it reloads, it will already save the "data name" automatically :(
Not if the initial source address of the IFRAME is a "dummy" one ;)
You have to reload the IFRAME to a different address, which will save the row.

Re: saving to database after few seconds questions

Posted: Thu Oct 23, 2008 9:31 am
by iory
i see :D , thats quite tricky lol :P ...but i dont really know how to make that :(. im not really good though using PHP, just
a beginner one :? ..im thinking of using microtime() function, but didnt know how to apply that one..

Re: saving to database after few seconds questions

Posted: Thu Oct 23, 2008 9:35 am
by VladSun
It's not a PHP issue - it's a HTML solution ;)

Dummy page:

Code: Select all

<html><head><meta http-equiv="refresh" content="5;url=http://yoursite.com/save_row.php"></head><body></body></html>
You already know how to write the save_row.php ...

Re: saving to database after few seconds questions

Posted: Thu Oct 23, 2008 9:46 am
by iory
i dont think that will work, because after it show [".$show['title_registration']."],
it immediately insert the ['title_registration'] into the database. Steps of this script will be,
user will make lots of selection, then the result is the ['title_registration'].

secondly, im using ( $_GET[page] ) function, so this script doesnt have the HTML entities at the top :(
do you have any idea with this @VladSun ? any comment will be appreciated :)