Jump to content

Recommended Posts

::) 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  :shrug: )

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

Link to comment
https://forums.phpfreaks.com/topic/212917-masters-of-php-help-me-please/
Share on other sites

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 :)

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.

I just did a small test with the following and it worked, hope it helps you.  :shy:

 

<!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>

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>

 

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

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 = ' ..

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.