Log in

View Full Version : [PHP/MySQL] Timestamps



Drompo
13-05-2007, 06:46 PM
How would you go about creating a VIP system. For example a member has 50 credits and Blue VIP costs 50 credits they click "Buy This" and they get vip for 30 days.

How would you do that last bit where it inserts ? into the database and counts down the days left until renewal.
And when it ends the Username markup goes back to normal.

+rep
Ash

@xP
13-05-2007, 06:52 PM
Sorry i don't have a clue what you are going on about :(

Edited by Bomb-Head (Forum Moderator): Please don't post pointlessly, thanks :)

Drompo
13-05-2007, 07:01 PM
Please only post if you know what your on about.
I want to know how would i go about making a VIP system

daftmoo
13-05-2007, 11:13 PM
Hi there,

Your best bet is to have the database know when the user signed up for VIP - that way, you could then setup a cron job to run nightly and remove the VIP when 30 days are over.

Alternatively, and probably the least resource-hungry method would be to check this value upon login. That makes it easier to show the user a message alerting them that their membership is no more.

DJ-Louis
13-05-2007, 11:15 PM
You need to no mysql and php advanced

Baving
13-05-2007, 11:26 PM
To work out the 30 days just do something like: -



<?
$expire = time()+2592000;
?>


Then to work out if it has expired or not: -



<?

$sql = "select * from tablename where user_id = '". $user ."' limit 1";
$query = mysql_query($sql); if(!$query) { die(mysql_error()); }
$vip = mysql_fetch_array($query);

if($vip['expire']<time()) {

echo "VIP Expired";

}else{

echo "VIP Inuse!";

}

?>


The code above doesn't exactly use much system resource so it can be checked on each page click so no cron jobs are required.

Drompo
14-05-2007, 03:46 PM
Thanks, +rep to alan and datfmoo

Want to hide these adverts? Register an account for free!