Active
Project:
Content Profile
Version:
6.x-1.0-beta4
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
4 Oct 2011 at 17:14 UTC
Updated:
4 Oct 2011 at 17:14 UTC
Hello
I am trying to devise a sql query to show me the ratio of men:women who have flagged a node.
I have the sql query pretty much down, although the query is aimed at core profile fields, and not content profile.
I need help in altering this query to pull from the correct tables.
The content profile field I am looking to draw the data from is in the UProfile Content Type.
Label: Gender
Name: field_gender
Type: Text (select box)
Right now, It is not a required field.
Here is the query I need altered:
<?php
$wherearewe = menu_get_object();
$nid = $wherearewe->nid;
$flagfid = 1; // This is the ID of the flag.
$profilefid = 1; // This is the id of the profile field.
$timespan = 3600; // One hour.
$total = db_result(db_query('SELECT COUNT(fcid) FROM {flag_content} WHERE fid = %d AND content_id = %d AND timestamp > %d', $flagfid, $nid, time() - $timespan));
$male = db_result(db_query("SELECT COUNT(f.fcid) FROM {flag_content} f LEFT JOIN {profile_values} p USING (uid) WHERE f.fid = %d AND p.fid = %d AND f.content_id = %d AND f.timestamp > %d AND p.value ='Male'", $flagfid, $profilefid, $nid, time() - $timespan));
$female = db_result(db_query("SELECT COUNT(f.fcid) FROM {flag_content} f LEFT JOIN {profile_values} p USING (uid) WHERE f.fid = %d AND p.fid = %d AND f.content_id = %d AND f.timestamp > %d AND p.value ='Female'", $flagfid, $profilefid, $nid, time() - $timespan));
$malepct = round($male / $total * 100);
$femalepct = round($female / $total * 100);
$out = t('Flagged by %total persons (%malepct% male, %femalepct% female)', array('%total' => $total, '%malepct' => $malepct, '%femalepct' => $femalepct));
return $out;
?>
Also, here is a link to the original post where I receievd the code from: http://drupal.org/node/1298376
Any assistance is GREATLY appreciated!!
thanks
Chris