alesyt0h Posted December 9, 2013 Share Posted December 9, 2013 Hello! 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: function time_reset() { $now = time(); DB::select('accounts'); $timer = DB::fetch_row(); $timer = $timer['reset_timer']; $difference = ($now - $timer); return (2629743 - $difference); } 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! Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 9, 2013 Share Posted December 9, 2013 (edited) Because this DB::select('accounts'); $timer = DB::fetch_row(); Is first getting all the accounts from the accounts table. Then on the next line it gets the first result from the table which will always be the first record in the table. You need to change your query so it only gets the record for the user you are renewing the membership to. Also if you used a date time field mysql can update the reset_timer field using one query like this UPDATE accounts SET reset_timer=DATE_ADD(CURDATE(), INTERVAL 1 MONTH) WHERE id=$user_id Edited December 9, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
alesyt0h Posted December 9, 2013 Author Share Posted December 9, 2013 Hello Ch0cu3r, thank you for the reply! So what I need to change? reset_timer field for default is 0 value. When someone purchase one month of premium is used by php with this: UPDATE accounts SET reset_timer = '$time' WHERE username = '$username'"; So everyone that purchases premium have a long numbers in reset_timer field. What I need to change in the php for select each record in the table? Thx! Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 9, 2013 Share Posted December 9, 2013 You need to change the time_reset() function so it gets the record that matches the users username to get their rest_timer value. As it stands now it is always getting the first record. Quote Link to comment Share on other sites More sharing options...
alesyt0h Posted December 9, 2013 Author Share Posted December 9, 2013 But what to change? I don't know nothing about php scripting :/ I only modify some files but little for fix it. Just I need to delete this line: $timer = DB::fetch_row(); Thx Quote Link to comment Share on other sites More sharing options...
alesyt0h Posted December 10, 2013 Author Share Posted December 10, 2013 Please help! Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 10, 2013 Share Posted December 10, 2013 (edited) I have told you what needs to be done. If you do not understand PHP then get someone else to modify the code for you, Freelance forum Edited December 10, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
alesyt0h Posted December 10, 2013 Author Share Posted December 10, 2013 Okay thx7 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.