saving to database after few seconds questions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
iory
Forum Newbie
Posts: 4
Joined: Thu Oct 23, 2008 8:09 am

saving to database after few seconds questions

Post 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? :(
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: saving to database after few seconds questions

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
iory
Forum Newbie
Posts: 4
Joined: Thu Oct 23, 2008 8:09 am

Re: saving to database after few seconds questions

Post 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 :(
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: saving to database after few seconds questions

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
iory
Forum Newbie
Posts: 4
Joined: Thu Oct 23, 2008 8:09 am

Re: saving to database after few seconds questions

Post 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..
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: saving to database after few seconds questions

Post 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 ...
There are 10 types of people in this world, those who understand binary and those who don't
iory
Forum Newbie
Posts: 4
Joined: Thu Oct 23, 2008 8:09 am

Re: saving to database after few seconds questions

Post 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 :)
Post Reply