PHP Script for 30 days premium

I have a site with premium memberships, but PHP script is not working well…

I the table accounts I have a column called reset_timer(default value is 0). When someone purchase a new premium membership, PHP add with time(); function into the reset_timer.

Premium is 1 month yes and is working well, but the “countdown” script is not working, the script take only the first reset_timer value so for example if the user1 purchase premium membership today, after 5 days, he have 25 days left, but if somebody in another account purchase 1 month of premium, he have 25 days left too, because script only taking the first reset_timer value… This is the code:

[php]function time_reset()
{
$now = time();
DB::select(‘accounts’);
$timer = DB::fetch_row();
$timer = $timer[‘reset_timer’];
$difference = ($now - $timer);
return (2629743 - $difference);
}[/php]
This is my table structure:

How I can do it for the script look in every account and reset timer for work correctly?

Thank you very much!

you can’t just fetch a row, it will always fetch the first row as you see. you need to run a mysql query and SELECT the row where ID = whatever id you are looking for. that means your time_reset function needs an id variable also. I don’t know your db functions but something similar to:
[php]<?php
function time_reset($id)
{
$now = time();
DB::select(‘accounts’);
$timer = DB::query(“SELECT * from accounts WHERE ID = $id”);
$timer = $timer[‘reset_timer’];
$difference = ($now - $timer);
return (2629743 - $difference);
}
then to tell it to reset a specific one (id = 27)
$reset = time_reset(27);
[/php]

replace 27 with a variable that passes the current users id.

Hello! thanks for reply!

But it makes me some errors that fix…
Says: Undefined variable: id , because another files are using time_reset function for … show how many days left in premium example: line on those files is time_reset(); but if I change time_reset($id); says that, undefined variable…

Thank you for help!

You have to do the same thing, you’re not displaying the right timer. some kind of id has to be passed to the query so it can find the right timer. Its telling you that $id doesn’t exist because it probably doesn’t until its called. You should be storing that id in a cookie or session variable when the person logs in, then when you need it, you simply call it.

I don’t know what you mean… what I need to change in php script?, whats the code? my knowledge about php is not good…

An undefined variable error is telling you that a variable is being seen before there’s anything tied to it and can generally be ignored since you get them all the time. But, in this case, it actually means something. The other guy tested your script outside out of the actual site and had to hardcode an id, and you copied his code, including his id example. Well, $id doesn’t exist since its not being defined anywhere. $id can be commented out or deleted completely.

I don’t know how you’re calling that time reset function, but some how, you need to pass the reset time function the id of the record for the person you’re trying to display the info for.

Just I need a code… I can’t make any code just with explains im so noob.

So what i do??

Sponsor our Newsletter | Privacy Policy | Terms of Service