Author Topic: Question: Deducting Points Automatically  (Read 6619 times)

Offline Veej

Question: Deducting Points Automatically
« on: May 02, 2006, 03:58:46 am »
Hey fellow SMF Shop users!

I had a question and I'm hoping someone might be able to help me out.

Can I make a script that will automatically deduct a number of points from members in a selected group every time I run it - or even better, can it be programmed to this once every month?

My PHP knowledge is limited but basically what I want it to do is...
if [member] = [group: Members]{
$points -50}
if [member] = [group: Members]{
$points >50
echo '[member_name] does not have enough points]}



So basically, if a member is in the group 'members' - it should deduct a value of 50 from the points field then the second part is if a member in the group 'member' has less than 50points, then print (or echo/show) his member name.
$points is just what I presumed the points variable will be, although this may well be wrong.

I'd like to know if this can easily be done and if someone could do it for me or tell me how to do it.

Please PM me for my MSN IM address if you are willing to help me with this!
Thanks! O0

Offline Basil Beard

Re: Question: Deducting Points Automatically
« Reply #1 on: May 02, 2006, 04:48:51 am »
You would need a cron job to run in monthy, but I think the code you are looking for would be
Code: [Select]
$result = db_query("SELECT ID_MEMBER
                                     FROM {$db_prefix}members
                                     WHERE $row['ID_GROUP'] = [i]Find the ID of the group you are talking about and insert it here[/li]", __FILE__, __LINE__);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
     $fee = 50;
     $result = db_query("UPDATE {$db_prefix}
                                          SET money = money - $fee
                                          WHERE ID_MEMBER = {$row['ID_MEMBER']}", __FILE__, __LINE__);
}
Arrrrr!

Offline Veej

Re: Question: Deducting Points Automatically
« Reply #2 on: May 04, 2006, 05:52:19 am »
Thanks for the prompt reply and sorry for my late reply! But, here goes:
Code: [Select]
$result = db_query("SELECT ID_MEMBER
                                     FROM {$db_prefix}members
                                     WHERE $row['1'] = [i]Find the ID of the group you are talking about and insert it here[/li]", __FILE__, __LINE__);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
     $fee = 20;
     $result = db_query("UPDATE {$db_prefix}
                                          SET money = money - $fee
                                          WHERE ID_MEMBER = {$row['ID_MEMBER']}", __FILE__, __LINE__);
}

This is what I have - group 1 mean Admin. Could you tell me if this works?

I'm new to PHP, but I cannot seem to find where it will display members who do not have enough points, I apologise if I'm wrong!

Basically, this is for a Post2Host, and I want it to automatically take away points from members, and display the member who do not have enough points so action can be taken.

Thanks a lot for your help! I greatly appreciate it :)

Offline Veej

Re: Question: Deducting Points Automatically
« Reply #3 on: May 05, 2006, 12:54:03 am »
Update: I thought nothing could go drastically wrong so I tried it out but got this error:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/rfh/public_html/boards/deduct.php on line 4

I think I have changed the wrong variables or not changed them all to match my forum.

Please could you tell me what I have to change.

Thanks.

Offline Daniel15

Re: Question: Deducting Points Automatically
« Reply #4 on: May 05, 2006, 09:40:43 pm »
Here, try this:
Code: [Select]
<?php
include("SSI.php");

echo 
"Credit Deduction script started at ".date("d/m/Y h:i:s A");

//Update money count of users
$result db_query("UPDATE {$db_prefix}members
                                          SET money = money - 50
                                          WHERE ID_GROUP = '1' "
__FILE____LINE__);

//Check for users that are under 50 credits
$result db_query("SELECT memberName 
                                          FROM 
{$db_prefix}members
                                          WHERE money < 50"
__FILE____LINE__);

echo 
"The following members have less than 50 credits: <br />";
while (
$row mysql_fetch_array($resultMYSQL_ASSOC)) {
    echo 
$row['memberName']."<br />";
}
?>

I haven't tried it, but it should work ;)

Offline Veej

Re: Question: Deducting Points Automatically
« Reply #5 on: May 06, 2006, 12:29:04 am »
Thanks Daniel, it worked great!

Just one thing however, when it is returning the list of members who have less than 50points, can you make it so that it only displays members in group '1' with less than 50 points please?

Oh and thanks so much for your help! You guys rock!  :smitten:

EDIT - Thanks, I managed to do it after looking up a bit about mySQL - I recommend this site (http://www.keithjbrown.co.uk/vworks/mysql/mysql_p1.shtml) if any newbies such as myself need help with things like this.

I ended up changing this part:

//Check for users that are under 50 credits
$result = db_query("SELECT memberName FROM {$db_prefix}members WHERE money < 50 AND ID_GROUP = '1' ", __FILE__, __LINE__);


^^
I specified 2 conditions instead of one using the AND operator.

Update - is there any way I can password protect this so no one else can use the script? (I have cPanel)
« Last Edit: May 06, 2006, 01:12:44 am by Veej »

Offline Daniel15

Re: Question: Deducting Points Automatically
« Reply #6 on: May 06, 2006, 10:09:57 am »
cPanel has a 'Password Protect Directory' function already built in... You could put the script in a subfolder, change the include("SSI.php"); to include("../SSI.php");, and password protect that directory. This is probably the easiest method.

Offline Veej

Re: Question: Deducting Points Automatically
« Reply #7 on: May 07, 2006, 12:59:32 am »
Ah, ok.

Thanks for that, I shall try that and get back to you once I have!

Offline Veej

Re: Question: Deducting Points Automatically
« Reply #8 on: May 07, 2006, 04:38:11 am »
I tried that but got this error:
Code: [Select]
Warning: main(/SSI.php): failed to open stream: No such file or directory in /home/rfh/public_html/forum/deductions/deduct.php on line 5

Warning: main(/SSI.php): failed to open stream: No such file or directory in /home/rfh/public_html/forum/deductions/deduct.php on line 5

Warning: main(): Failed opening '/SSI.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/rfh/public_html/forum/deductions/deduct.php on line 5
Credit Deduction script started at 06/05/2006 08:35:47 PM
Fatal error: Call to undefined function: db_query() in /home/rfh/public_html/forum/deductions/deduct.php on line 10

Offline Daniel15

Re: Question: Deducting Points Automatically
« Reply #9 on: May 07, 2006, 02:30:06 pm »
OK, try changing the include("SSI.php"); to include the full path to SSI.php. For example:  include("/home/daniel15/public_html/forum/SSI.php");

Offline Veej

Re: Question: Deducting Points Automatically
« Reply #10 on: May 07, 2006, 05:21:57 pm »
Thanks Dan, it worked :)

Keep up the excellent work!

Offline Daniel15

Re: Question: Deducting Points Automatically
« Reply #11 on: May 12, 2006, 07:18:11 pm »
No problem ;)