Jump to content

[SOLVED] Voting


everlifefree

Recommended Posts

Here's my voting code but I can't figure out to make it do more than just compute the average I want it to add 1 if the click on they 1 button and -1 in they click on the -1 button. Please help

 

// COMPUTE RATINGS ///////////
if (!is_array($rating = unpk($row["rating"]))) $rating = array();

if (me("id") > 0 and in_array(me("id"), array_keys($rating))) $tpl -> Zone("rating", "disabled");
else {

	if (isset($_GET["rate"]) and $_GET["rate"] > -2 and $_GET["rate"] < 2 and is_numeric($_GET["rate"])) {
		$rating[me("id")] = $_GET["rate"];
		myQ("
			UPDATE `[x]nark` 
			SET 
				`rating`='".pk($rating)."',
				`rating_hits`='".count($rating)."',
				`rating_avg`='".round(array_sum($rating) / count($rating), 1)."'
			WHERE `id`='{$row["id"]}' 
			LIMIT 1
		");

		$GLOBALS["CHROMELESS_MODE"] = true;

		$tpl -> LoadThis($tpl -> Zone("rating", "disabled", 1));
		$tpl -> AssignArray(array(
			"rate.hits" => count($rating),
			"rate.avg" => round(array_sum($rating) / count($rating), 1)
		));
		$tpl -> Flush();
		die();
	}
}

$tpl -> Zone("rating", "enabled");
$tpl -> AssignArray(array(
	"rate.hits" => count($rating),
	"rate.avg" => (count($rating) > 0 ? round(array_sum($rating) / count($rating), 1) : 0)
));

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.