xkaser101 Posted September 8, 2010 Share Posted September 8, 2010 i have just joined this for and i am desperate for help, I am sure what i want is pretty easy, but you judge. What i want is a code to add certain amount of numbers ( points ) when a user visits it. i already have a mysql database with fields like , username , Id , Password and Points, how can i create a simple code to just add lets say +10 points when he register to my Feed ? and i will really be grateful if you give me a code so that they do that once every 24 only. ( i know it's done using timestamps but how ) I already posted this on several forums but some dudes wanted money for this and i don't really think it is worth 100$ for less than 10 lines code. Best Regards ! Thanks In advance, Issa K Quote Link to comment https://forums.phpfreaks.com/topic/212917-masters-of-php-help-me-please/ Share on other sites More sharing options...
fortnox007 Posted September 8, 2010 Share Posted September 8, 2010 Well what you could do is go to alpha userpoints and look at their source code. Its a joomla component that gives points based on rules, like reading an article, daily login etc. I am still to new to programming to write this myself but that is ready made and works. And maybe nice to learn from. -edit: if you want it automated i am pretty sure you need cronjobs. but I have no Idea how. All I can think of is do an sql query Update Table Where signed_up is TRUE SET points = points + 20 or something like that. here is a basic tutorial on sql I used recently: http://www.firstsql.com/tutor4.htm And than its pretty easy i think if noone knows something better ill try to write something for you tomorrow, but I am not yet an expert Quote Link to comment https://forums.phpfreaks.com/topic/212917-masters-of-php-help-me-please/#findComment-1108963 Share on other sites More sharing options...
pengu Posted September 9, 2010 Share Posted September 9, 2010 If you have a login system this should be really easy for you, I should hope. You just need a couple of queries. Maybe add another field for your table and call it RSSChecked, it can be either 1 or 0. Do a query to get the RSSChecked field, if it's a 0 Do this.. <?php $sql = "UPDATE users SET points = points + 10 WHERE username = 'username' "; ?> If it's a 1, do nothing. Quote Link to comment https://forums.phpfreaks.com/topic/212917-masters-of-php-help-me-please/#findComment-1108967 Share on other sites More sharing options...
fortnox007 Posted September 9, 2010 Share Posted September 9, 2010 I just did a small test with the following and it worked, hope it helps you. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>practice</title> </head> <body> <?php $dbc = mysqli_connect('localhost','user','pass','db') or die('could not connect to database'); echo 'connected'; // i am using a table named users, and a field named subcribed // your rss subscribe script should have something to set subscribed to 1 ofc $query = "UPDATE users SET points = points + 10 WHERE subscribed = 1 "; $result = mysqli_query($dbc, $query) or die ('error executing query'); mysqli_close($dbc); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/212917-masters-of-php-help-me-please/#findComment-1108978 Share on other sites More sharing options...
petroz Posted September 9, 2010 Share Posted September 9, 2010 You could also add a "AND" statement to check a timestamp and make sure it hasnt been updated in the past 24 hours. Quote Link to comment https://forums.phpfreaks.com/topic/212917-masters-of-php-help-me-please/#findComment-1108981 Share on other sites More sharing options...
fortnox007 Posted September 9, 2010 Share Posted September 9, 2010 Is that easy to do? or should you first use time () in php and than do some math Quote Link to comment https://forums.phpfreaks.com/topic/212917-masters-of-php-help-me-please/#findComment-1108985 Share on other sites More sharing options...
petroz Posted September 9, 2010 Share Posted September 9, 2010 LOL... well yes, there would be some minor math.. but it would go something like this.. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>practice</title> </head> <body> <?php $time = time(); //unix time.... $update_time = $time - 86400; //current time minus 1 day or 86400 seconds... $dbc = mysqli_connect('localhost','user','pass','db') or die('could not connect to database'); echo 'connected'; // i am using a table named users, and a field named subcribed // your rss subscribe script should have something to set subscribed to 1 ofc $query = "UPDATE users SET points = points + 10 WHERE subscribed = 1 AND updated > '$update_time'"; //note that your database will have to have a field of when the users last updated and store the time in a unix timestamp format. $result = mysqli_query($dbc, $query) or die ('error executing query'); mysqli_close($dbc); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/212917-masters-of-php-help-me-please/#findComment-1108989 Share on other sites More sharing options...
fortnox007 Posted September 9, 2010 Share Posted September 9, 2010 at the SQL forum i found maybe something I haven't tested it but it looked wicked without math timestamp BETWEEN NOW() - INTERVAL 1 DAY AND NOW() So it would maybe look like this: $query = "UPDATE users SET points = points + 10 WHERE subscribed = 1 AND timestamp BETWEEN NOW() - INTERVAL 1 DAY AND NOW() Lol if that works i am gonna make myself a cake Quote Link to comment https://forums.phpfreaks.com/topic/212917-masters-of-php-help-me-please/#findComment-1108990 Share on other sites More sharing options...
petroz Posted September 9, 2010 Share Posted September 9, 2010 That sure is pretty... gonna run a test of that later! Good find. Quote Link to comment https://forums.phpfreaks.com/topic/212917-masters-of-php-help-me-please/#findComment-1108991 Share on other sites More sharing options...
fortnox007 Posted September 9, 2010 Share Posted September 9, 2010 Thx btw Petroz I love this forum, one progressive learning curve for me : ) Quote Link to comment https://forums.phpfreaks.com/topic/212917-masters-of-php-help-me-please/#findComment-1108992 Share on other sites More sharing options...
petroz Posted September 9, 2010 Share Posted September 9, 2010 I am totally addicted.. Quote Link to comment https://forums.phpfreaks.com/topic/212917-masters-of-php-help-me-please/#findComment-1108993 Share on other sites More sharing options...
fortnox007 Posted September 9, 2010 Share Posted September 9, 2010 I second that Quote Link to comment https://forums.phpfreaks.com/topic/212917-masters-of-php-help-me-please/#findComment-1108994 Share on other sites More sharing options...
ignace Posted September 9, 2010 Share Posted September 9, 2010 subscribe-feed.php $sql = 'INSERT INTO point_system_actions (user_id, action_name, action_taken_on) VALUES (' ... if(mysql_query($sql)) { $sql = 'UPDATE point_system SET points += 10 WHERE user_id = ' .. login.php $sql = 'INSERT INTO point_system_actions (user_id, action_name, action_taken_on) VALUES (' ... // unique idx_action (user_id, action_name, action_taken_on) if(mysql_query($sql)) { $sql = 'UPDATE point_system SET points += 10 WHERE user_id = ' .. Quote Link to comment https://forums.phpfreaks.com/topic/212917-masters-of-php-help-me-please/#findComment-1109118 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.