Jump to content

How to retrieve user point in all pages.


zap0paz

Recommended Posts

Hi everyone and thank you for your time to response and reading this question. As a newbie here, I'd like to thank to the authors of this website. So the question is this one: I use the following code to appoint a score to the user. ( wordpress plugin )

}
function set_best_answer_and_report(){
global $wpdb,$userdata,$answers;
if($_GET["report"]){
	$report=$_GET["report"];
	if($userdata->ID){
	$p=$_GET["p"];
	$wpdb->query("UPDATE ".$wpdb->comments." SET reported=1 WHERE comment_ID=$report");
	}
}
if($_GET["ba"])
{
	$ba=$_GET["ba"];
	$comment= get_comment($ba);
	$p=$comment->comment_post_ID;
	$data=get_postdata($p);


	$commentdata=get_comment($ba);
	if($data["Author_ID"]==$userdata->ID and $data["comment_status"]!="closed")
	{
	$user=get_userdata($commentdata->user_id);
	$wpdb->query("UPDATE ".$wpdb->comments." SET ba=1 WHERE comment_ID=$ba");
	$wpdb->query("UPDATE ".$wpdb->posts." SET comment_status='closed' WHERE ID=$p");
	$qya_options=get_option("qya_options");
	if(isset($user->qya_points)){
	 	$points=$user->qya_points;
	 }else{
		$points=0;
	}
	update_usermeta($commentdata->user_id,"qya_points",$points+$qya_options["qya_extrappa"]);

	}

}
}

I input this code in loggedin-in.php in order to echo the score of the user always on the sidebar: (Logged in is a login widget which is always on the sidebar and sidebar is always on all the pages viewed, except 1.)

 

<?php the_points();?>

 

When I'm in the index page, it shows my score correct. However, when I move to the another page, where sidebar is still existing, my score either becomes 0 or the different user's score, mainly who has the least score. How can I fix this issue?

 

extra info about the_points function:

 

}
function the_points(){
	global $authordata,$profiledata;
	if($authordata->qya_points!=""){
		echo $authordata->qya_points;
	}else{if($profiledata->qya_points!=""){
		echo $profiledata->qya_points;
		}else
		{
		echo 0;
		}

	}
}

Link to comment
Share on other sites

The code you provided really doesn't tell me anything about how the value is obtained or used. All I see are a bunch of UPDATE queries. I would expect to see a SELECT query to obtain the points value and then store it somewhere that will be available from page load to page load. If you are storing it in the database then you need to be SELECTing it on each page load.

 

So, you can either store the value in the database and extract it on each page load for the user or you can store the value in a SESSION or COOKIE value. Each solution has its benefits and drawbacks.

Link to comment
Share on other sites

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.