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
https://forums.phpfreaks.com/topic/85308-solved-voting/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.