If that makes sense
COUNTDOWN
Moderator: General Moderators
I agree in that JS would give you a "prettier" counter (you could count in realtime), but if it's going to need to be specific to each user, you'd be best suited to use a combination of JS and php.
do as Skara suggested and stamp the time if their original visit (or whatever you want to count FROM).
do that in mysql:
then fetch that time and send it down to the client to start your JS timer. I'm sure there are a million JS timers out there that you could use for code...google it.
do as Skara suggested and stamp the time if their original visit (or whatever you want to count FROM).
do that in mysql:
Code: Select all
mysql_query("e;insert into myTable (time) values (now())"e;)
or die(mysql_error());2 options:Parody wrote:The whole idea of the countdown is so that the user cannot visit the same page within a certain amount of time.
- use cookie: user can only go back to that page after cookie expired. however, this method is not secure - someone can delete the cookie if he knows how to.
- php/mysql: save time when he first goes to the page, and when he revisited. check the first time record with the current time.
Make sure you have a field in the database that is set up as a time or a datetime then use:
that will stamp the current time on the server.
then to recall it just select off the table with a normal select statement and you can format the time however you want using php's date() function.
Code: Select all
insert into myTable (myTimeField) values (now())then to recall it just select off the table with a normal select statement and you can format the time however you want using php's date() function.
when you're creating the table, (assuming you're using phpMyAdmin), select "time" or "datetime" from the field type list ie: varchar, char, text, longtext, etc..
if you're doing it from the command line on an already existing table, use something like this:
if you're doing it from the command line on an already existing table, use something like this:
Code: Select all
ALTER TABLE myTable ADD COLUMN myTimeField time AFTER whateverFieldYouWantThisAfterok then try this:
edit: if you want the field at the end...then just leave off the the after portion.
Code: Select all
mysql_query("ALTER TABLE myTable ADD COLUMN myTimeField time AFTER whateverFieldYouWantThisAfter")
or die(mysql_error());So... If I wanted to add it into something like this:
If I wanted for example the value 'jail' to be time I just do this:
Code: Select all
$create = CREATE TABLE stats (username varchar(40),character int(2) DEFAULT '01' NOT NULL,health int(3) DEFAULT '100' NOT NULL,money int(100) DEFAULT '2000' NOT NULL,rank int(3) DEFAULT '01' NOT NULL,level int(2) DEFAULT '001' NOT NULL,respect int(3) DEFAULT '001' NOT NULL,house int(2) DEFAULT '01',cstat int(3) DEFAULT '001' NOT NULL,gstat int(3) DEFAULT '001' NOT NULL,status int(1) DEFAULT '1' NOT NULL,jail int(1) DEFAULT '0' NOT NULL,PRIMARY KEY (username))"e;;Code: Select all
jail time DEFAULT '0' NOT NULL