Thankfully, MinnesotaPlaylist provides...
'Other' responses:
';
$key = 'like';
$nid = '9066';
$sql = "select count(a) from {survey10} where q='%s' and uid=%d";
$count = db_result(db_query($sql, $key, $user->uid));
if (isset($_POST['submit']) && ($_POST['flag_id']==$nid)) {
for ($i=1; $i<=13; $i++) {
if (!empty($_POST[$i])) {
if (($i == 13) && (!empty($_POST['other']))) {
$sql = "insert into {survey10} (uid, q, a, other) values (%d, '%s', '%s', '%s')";
db_query($sql, $user->uid, $key, $_POST[$i], $_POST['other']);
} else {
$sql = "insert into {survey10} (uid, q, a) values (%d, '%s', '%s')";
db_query($sql, $user->uid, $key, $_POST[$i]);
}
}
}
print 'Thanks for taking our survey. Your answer has been included in the results below.';
} else {
if ($user->uid) {
if ($count == 0) {
?>
';
$sql = "select count(*) from (select distinct uid from {survey10}
where q = '%s') as users";
$count = db_result(db_query($sql, $key));
if ($count>0) {
$n=0;
$word = array();
$qty = array();
$sql = "select a as word, count(uid) as qty from {survey10} where q='%s' group by word";
$result = db_query($sql, $key);
while($data = db_fetch_object($result)) {
$word[$n] = $data->word . ' (' . 100 * (number_format($data->qty / $count, 2)) . '%)';
$qty[$n] = 100 * $data->qty/$count;
$n=$n+1;
}
$values = implode(',', $qty);
foreach($word as $i=>$val) {
$labels = $labels . 't ' . $val . ',166665,0,' . $i . ',12|';
}
$labels = substr($labels,0,strlen($labels)-1);
$max_val = (intval((max($qty)/.7)/5)+1)*5;
$interval = round($max_val/5);
print '';
$sql = "select other, count(*) as count_other from {survey10} where q='%s' and other > '' group by other order by count_other desc";
$result = db_query($sql, $key);
if (!empty($result)) {
print "";
while ($data = db_fetch_object($result)) {
print '
';
}
}
?>