Hoping I can get some help with some code for the Voting API module. I am using hook_votingapi_result_alter() to try to calculate the percent of a certain demographic that is voting on a node. Upon registration, individuals are identifying whether they are "Male" or "Female." I am then running a db_query to pull this information and recalculate the results to determine % of men and % of female voting on each node. However, when I run the code below, it seems whichever if statement comes first (male or female) is getting auto incremented regardless of whether it a male or female submitting the vote. Any thoughts on why this is happening would be helpful or if anyone sees a series flaw in logic in performing this result_alter() it would be greatly appreciated.

<?php
/**
* Implementation of hook_votingapi_results_alter().
*/
function mymodule_votingapi_results_alter($cache, $content_type, $content_id) {
// Pulling in male or female from personal profile
$created = db_query("SELECT value FROM {profile_values} WHERE uid = %d");
// Auto increment male / female
if ($created="Male") {
$male++;
}
elseif ($created="Female") {
$female++;
}

// Cache the results.
$cache['vote']['points']['percent_male'] = $male / ($male + $female);
$cache['vote']['points']['percent_female'] = $female / ($male + $female);
}

Comments

Scott Reynolds’s picture

Use '==' instead of '=' in your if

if ($created == "Male")
Starvin15’s picture

Status: Closed (fixed) » Active
Scott Reynolds’s picture

Status: Active » Closed (fixed)

Guess would be its not 'Male' but 'male'

But this isn't a PHP help forum. please take your questions elsewhere.

Status: Active » Closed (fixed)