...

View Full Version : Max Points



mrnightowl
07-26-2007, 03:28 AM
I have a points system on my site. Using a database.
I don't want users to be able to go over 550pts by clicking links. Wondering if I coded this right.


$checkpoints = $userobj->GetTodayPoint($friend_id);
if($checkpoints>=550)
{
echo "You have reached your adding limit for today. Please post bulletins for more points";
exit();
}

where user_today_points in the database is self evident... is this proper way of saying if points greater than 550?

zro@rtv
07-26-2007, 04:32 AM
that should work fine, is it not?
http://www.w3schools.com/php/php_operators.asp

mrnightowl
07-26-2007, 05:04 AM
that should work fine, is it not?
http://www.w3schools.com/php/php_operators.asp

It is working now thanks... but my problem is I guess with the function to get SUM of total points for the day from adding users... the method I posted there gets total points from the day but not just from adding users. here the new function I tried to make


function AddPoints($friend_id)
{
global $ado;
$add_point = 0;
$today = date('Y-m-d');
$sql = "SELECT SUM(points) AS total FROM tbl_user_points
WHERE user_login_id='$friend_id'
AND
added_date='$today'";
points_for='adduser'";
$res = $ado->execute($sql);
$row = $ado->fetch($res);
if($row['point'] > 0)
$add_point = $row['point'];
}

This is the error I get from this
Parse error: parse error, unexpected '=' in /home/content/e/a/l/ealaut/html/classes/user.class.php on line 567

I just want from tbl_user_points under the points_for I just want to have it get points from adduser for today not from bulletin which is the other variable.

StupidRalph
07-26-2007, 06:30 AM
It would help if you said which line that was...

added_date='$today'";
points_for='adduser'";

Check your double quotes, you are terminating your SQL statement to early.

mrnightowl
07-26-2007, 06:59 AM
Your right ... don't know how I missed that ... I loaded up my script and a database on godaddy using a free hosting credit I had from registering the domain. I did correct that but now getting another error. I am very new to all this but I dont mind staying up all night to research and try to fix these errors.
My new error is:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; points_for='adduser' at line 4

Looking into that now. I dont see the problem but yeah... lol

StupidRalph
07-26-2007, 08:54 AM
I'm assuming that adduser is suppose to be a PHP variable. Try preceding it with a $. Actually, you should post your updated code so that I can evaluate it.



$sql = "SELECT SUM(points) AS total FROM tbl_user_points
WHERE user_login_id='$friend_id'
AND
added_date='$today'";
points_for='$adduser'";



P.S. - You're on programmers hours now :P. I just came back from Kinkos and its nearly 4am :o.

mrnightowl
07-26-2007, 09:06 AM
adduser is a database value..... under the tbl_user_points I have .. added_date and points_for which can be adduser,bulletin, or vote

what I want is for it to fetch on only adduser for todays date I don't want the total for bulletin or votes on todays date just the adduser

mrnightowl
07-26-2007, 09:09 AM
Here is another way I've tried to do it...


function AddPoints($friend_id)
{
global $ado;
$add_point = 0;
$today_point = 0;
$today = date('Y-m-d');
$sql = "SELECT SUM(points) AS point FROM tbl_user_points
WHERE user_login_id='$friend_id'
AND
points_for='adduser'";
$res = $ado->execute($sql);
$row = $ado->fetch($res);
if($row['point'] > 0)
$add_point = $row['point'];


$sql = "SELECT SUM(points) AS point FROM tbl_user_points
WHERE user_login_id='$friend_id'
AND
added_date='$today'";
$res = $ado->execute($sql);
$row = $ado->fetch($res);
if($row['point'] > 0)
$today_point = $row['point'];
$arr = array("add_point"=>$add_point,"today_point"=>$today_point);
return $arr;
}

StupidRalph
07-26-2007, 09:38 AM
Well you should be able to keep them both in the WHERE clause. I just noticed in the first example that you do not have a AND between the two conditions of the WHERE clause.




$sql = "SELECT SUM(points) AS total FROM tbl_user_points
WHERE user_login_id='$friend_id'
AND
added_date='$today'
AND
points_for='adduser'";

When troubleshooting queries, its a good thing to test directly in the database environment. That way, you can bypass some additional oversights. Were you receiving an error with the last two seperate queries?

mrnightowl
07-26-2007, 09:54 AM
Well you should be able to keep them both in the WHERE clause. I just noticed in the first example that you do not have a AND between the two conditions of the WHERE clause.




$sql = "SELECT SUM(points) AS total FROM tbl_user_points
WHERE user_login_id='$friend_id'
AND
added_date='$today'
AND
points_for='adduser'";

When troubleshooting queries, its a good thing to test directly in the database environment. That way, you can bypass some additional oversights. Were you receiving an error with the last two seperate queries?



AAAAAh YES... very good... works great thank you. Don't know if your still on but I did have another question. If you don't mind. Reason I'm doing all this is to prevent people from just being able to click away. One last thing I've been having a hard time figuring out is how to slow them down on clicking the links... I have this code:


<?PHP
//echo"$row_user[user_login_id]";
?>

<a class="fade" href="adduser.php?addid=<?=$row_user['user_login_id']?>&act=<?=$_GET['action']?>" target="_blank"><img src="<?=$row_user['user_picture']?>" width="100" height="100" border="0"></a>
<BR><a href="adduser.php?addid=<?=$row_user['user_login_id']?>&act=<?=$_GET['action']?>" target="_blank">Add</a> | <a target="_blank" href="http://myspace.com/<?=$row_user['user_login_id']?>">View</a>


Along with the other code to generate 25 links for them to click at a time... is there a php way to make them only be able to click a link every few seconds? or do I have to go with javascript or some other form to prevent them from clicking 10 or 20 links in a few seconds...

Thanks again for the help on clearing up my syntax problem....

StupidRalph
07-26-2007, 10:00 AM
Everytime someone clicks a link, you can store the time in a session variable. When they click another link you just compare whats in the session variable with the current time. If not enough time has passed then don't allow them to get points. If you want this check to take place on the client side (in the browser) then you'll have to use javascript (or vbscript, but lets be realistic).

Also, note that if you don't want them to CLICK the link then it'll have to be on the client-side (javascript). You'll have to write some type of function that basically does the same thing as described above except you would't use a session variable just a regular javascript variable. Also note, that if they're using javascript that they can simply turn off javascript and bypass this securtiy feature. One thing you can do is not make them hyperlinks, you can use javascript to activate them as hyperlinks. So if they have javascript turned off, it won't work anyway. :P



function hyperlink(link) {

window.open(link,location=0,status=0,scrollbars=1,menubar=yes,resizeable=yes,width=400,height=400');
}
.....

<a href="#" onclick="javascript: hyperlink('http://myspace.com/<?=$row_user['user_login_id']');?>">View</a>


Or something like that, I didn't test it, and I'm NO javascript person :P.

mrnightowl
07-26-2007, 10:09 AM
Ok cool I would actually prefer it to be client side ... for the fact I am trying to reduce server load...
so someting starting like this?


var timeStamp =
function checkClick(lclick)
var timeNow =

where I could put a onclick="checkClick" in the <a href>

StupidRalph
07-26-2007, 10:21 AM
Umm this is going to be the wrong forum to start this discussion but you can simply use javascripts Date() to get the time



var now = new Date()
var hours = now.getHours()
var minutes = now.getMinutes()
var seconds = now.getSeconds()


But as stated, I'm totally not the javascript person :P. I think you can actually use a timestamp as you've named one of your variables.

mrnightowl
07-26-2007, 10:22 AM
Everytime someone clicks a link, you can store the time in a session variable. When they click another link you just compare whats in the session variable with the current time. If not enough time has passed then don't allow them to get points. If you want this check to take place on the client side (in the browser) then you'll have to use javascript (or vbscript, but lets be realistic).

Also, note that if you don't want them to CLICK the link then it'll have to be on the client-side (javascript). You'll have to write some type of function that basically does the same thing as described above except you would't use a session variable just a regular javascript variable. Also note, that if they're using javascript that they can simply turn off javascript and bypass this securtiy feature. One thing you can do is not make them hyperlinks, you can use javascript to activate them as hyperlinks. So if they have javascript turned off, it won't work anyway. :P



function hyperlink(link) {

window.open(link,location=0,status=0,scrollbars=1,menubar=yes,resizeable=yes,width=400,height=400');
}
.....

<a href="#" onclick="javascript: hyperlink('http://myspace.com/<?=$row_user['user_login_id']');?>">View</a>


Or something like that, I didn't test it, and I'm NO javascript person :P.

Aaah ok yeah that would be a good idea...


var timeStamp = null;
function checkClick(lclick){}
var timeNow = new now.getMinutes() +":" + now.getSeconds()
if(timeNow - timeStamp > 10 seconds || timeStamp == null){
timeStamp = new now.getMinutes() +":" + now.getSeconds()
}
else
{
// clicked too fast
}
}

Guess something along that line but I'm poor in that myself trying to take this all in... not sure on the time vars but I can take it to the javascript board...

mrnightowl
07-26-2007, 10:24 AM
Well thank you very much again for all your help Ralph... Made my night/morning worth while knowing I'm getting somewhere.... Enjoy the rest of your week. Take care.

StupidRalph
07-26-2007, 10:26 AM
Seems like good pseudo-code to me. And just remember that they can disable javascript so don't rely on that totally, unless you were to implement something like the script I had above (well a better implementation of what I have above :P)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum