Thanks!
Now
I'm really confused

(I'm guessing though that I've been somewhat confused from the start here.)
Perhaps part of what's confusing here is that I only shared part of the code so that I could get it working with one topic. In reality, there are 5 topics, each one with the "same" variables, sort of:
- Topic 1
- ab1
- cd1
- ae1
- bd1
- ec1
- da1
- eb1
- ca1
- de1
- bc1
Topic 2
- ab2
- cd2
- ae2
- bd2
- ec2
- da2
- eb2
- ca2
- de2
- bc2
...
And so on for a total of 5 topics.
Each of those variables is named for the "choice" made on a form - e.g., the first variable "ab" was a choice between "a" and "b" (these letter represent images). Because of other requirements for scoring the data collected later, any choice on the left side of the column is equal to "1" and any choice on the right is equal to "2".
Here's the form code for that part to give a sense of part of the data I'm collecting:
Code: Select all
<td class="input">
<p>Topic 1:<br /><input type="text" name="topic1" /><br />
<p><input type="radio" name="ab1" value="1"/>A - B<input type="radio" name="ab1" value="2"/></p>
<p><input type="radio" name="cd1" value="1"/>C - D<input type="radio" name="cd1" value="2"/></p>
<p><input type="radio" name="ae1" value="1"/>A - E<input type="radio" name="ae1" value="2"/></p>
<p><input type="radio" name="bd1" value="1"/>B - D<input type="radio" name="bd1" value="2"/></p>
<p><input type="radio" name="ec1" value="1"/>E - C<input type="radio" name="ec1" value="2"/></p>
<p><input type="radio" name="da1" value="1"/>D - A<input type="radio" name="da1" value="2"/></p>
<p><input type="radio" name="eb1" value="1"/>E - B<input type="radio" name="eb1" value="2"/></p>
<p><input type="radio" name="ca1" value="1"/>C - A<input type="radio" name="ca1" value="2"/></p>
<p><input type="radio" name="de1" value="1"/>D - E<input type="radio" name="de1" value="2"/></p>
<p><input type="radio" name="bc1" value="1"/>B - C<input type="radio" name="bc1" value="2"/></p>
</td>
<td class="input">
<p>Topic 2:<br /><input type="text" name="topic2" /><br />
<p><input type="radio" name="ab2" value="1"/>A - B<input type="radio" name="ab2" value="2"/></p>
<p><input type="radio" name="cd2" value="1"/>C - D<input type="radio" name="cd2" value="2"/></p>
<p><input type="radio" name="ae2" value="1"/>A - E<input type="radio" name="ae2" value="2"/></p>
<p><input type="radio" name="bd2" value="1"/>B - D<input type="radio" name="bd2" value="2"/></p>
<p><input type="radio" name="ec2" value="1"/>E - C<input type="radio" name="ec2" value="2"/></p>
<p><input type="radio" name="da2" value="1"/>D - A<input type="radio" name="da2" value="2"/></p>
<p><input type="radio" name="eb2" value="1"/>E - B<input type="radio" name="eb2" value="2"/></p>
<p><input type="radio" name="ca2" value="1"/>C - A<input type="radio" name="ca2" value="2"/></p>
<p><input type="radio" name="de2" value="1"/>D - E<input type="radio" name="de2" value="2"/></p>
<p><input type="radio" name="bc2" value="1"/>B - C<input type="radio" name="bc2" value="2"/></p>
</td>
...and so on for 5 topics.
Then in the report, I need to get a "count" of how many times each letter was chosen for each topic.
So, for Topic 1 I want to know how many times was "A" chosen? I use $ia1 as the variable for that ("image" "a" for topic "1")
Code: Select all
//how many times was each image chosen for topic 1?
//get count of image a
$ia1 = 0;
if($_POST['ab1'] == 1){
$ia1 = $ia1 + 1;
}
if($_POST['ae1'] == 1){
$ia1 = $ia1 + 1;
}
if($_POST['da1'] == 2){
$ia1 = $ia1 + 1;
}
if($_POST['ca1'] == 2){
$ia1 = $ia1 + 1;
}
//get count of image b
$ib1 = 0;
if($_POST['ab1'] == 2){
$ib1 = $ib1 + 1;
}
if($_POST['bd1'] == 1){
$ib1 = $ib1 + 1;
}
if($_POST['eb1'] == 2){
$ib1 = $ib1 + 1;
}
if($_POST['bc1'] == 1){
$ib1 = $ib1 + 1;
}
//get count of image c
$ic1 = 0;
if($_POST['cd1'] == 1){
$ic1 = $ic1 + 1;
}
if($_POST['ec1'] == 2){
$ic1 = $ic1 + 1;
}
if($_POST['ca1'] == 1){
$ic1 = $ic1 + 1;
}
if($_POST['bc1'] == 2){
$ic1 = $ic1 + 1;
}
//get count of image d
$id1 = 0;
if($_POST['cd1'] == 2){
$id1 = $id1 + 1;
}
if($_POST['bd1'] == 2){
$id1 = $id1 + 1;
}
if($_POST['da1'] == 1){
$id1 = $id1 + 1;
}
if($_POST['de1'] == 1){
$id1 = $id1 + 1;
}
//get count of image e
$ie1 = 0;
if($_POST['ae1'] == 2){
$ie1 = $ie1 + 1;
}
if($_POST['ec1'] == 1){
$ie1 = $ie1 + 1;
}
if($_POST['eb1'] == 1){
$ie1 = $ie1 + 1;
}
if($_POST['de1'] == 2){
$ie1 = $ie1 + 1;
}
...and so on for all 5 topics.
Originally I got it working the long way, with a separate "copy" of that code for each topic (changing the "1" to the topic number in each case) - to lead to $ia1, $ib1, $ic1, $id1, $ie1, $ia2, $ib2... $id5, $ie5 as the 25 variables that are important for generating the charts and determining the "epitomizing" (most frequently chosen) and "antithetical" (least frequently chosen) images for each topic.
Anyway, so now I've changed that code to get the counts and got the "how many times was image x chosen for topic x" in a loop and also have the creation of the charts (1 per topic) in a loop.
I'm also collecting descriptions of the images (i.e., 1 description for each image = 5 descriptions total) - which will get displayed with the charts for each topic ONLY in the case that the image is epitomizing or antithetical for the topic. So, any given description could theoretically be displayed with the chart for every topic.
Here's the full code I've got now, that's working very well (there's more that comes after this, but it's not relevant to this issue):
Code: Select all
<?php
//get the class
include('FCharts/Class/FusionCharts_Gen.php');
$today = date("F j, Y");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="description" content="JOG Your Right Brain ~ A Holistic Assessment Tool for Business & Research - Using the Projective Differential to uncover the hidden attitudes and perceptions that influence behavior.">
<meta name="keywords" content="Projective Differential, JOG Your Right Brain, PD, PD-JOG, intuitive, unconscious, abstract, implicit, latent attitudes, perceptions, identification, assessment, projective differential, r-mode, l-mode, right-brain, left-brain, organizational culture, corporate culture, psychological">
<title>Strategy SIG ~ JOG Your Right Brain Personalized Report for <?php echo $_POST['name']; ?></title>
<script language='javascript' src='FCharts/FusionCharts/FusionCharts.js'></script>
<style type="text/css">
.pd_table {
text-align: center;
min-width: 100px;
}
.info {
margin: 10px 30px 10px 25px;
width: 75%;
}
.hyphen {
white-space: nowrap;
}
.images {
text-align: center;
}
.section {
margin-left: 5px;
padding-bottom: 10px;
}
.chart {
float:left;
margin:0 0 15px 20px;
width: 75%;
padding:15px;
border:1px solid black;
text-align:center;
clear: both;
}
.charttxt {
text-align:left;
}
blockquote {
font-style: italic;
padding: 5px 15px 5px 25px;
margin: 0px 25px 0px 150px;
background-color: #eeeeee;
}
.img {
float:left;
padding-right: 10px;
}
.epitimage {
margin: 0 5px 25px 5px;
align: top;
border-bottom: 1px dotted #999999;
padding-bottom: 5px;
min-height: 87px;
}
h2,h3 {
background-color: #3062C4;
color: #fff;
padding-left: 10px;
width: 80%;
}
.incong{
width: 40%;
color: #3062C4;
border-top: 1px solid #57AC0B;
border-bottom: 1px solid #57AC0B;
background: #f6f6f6;
padding-top: 5px;
}
.enddiv {
clear:both;
}
.raw_data {
border-top: 1px dashed;
padding-top: 5px;
}
.small {
font-size: 10px;
text-align: center;
}
</style>
</head>
<body>
<div class="section" id="intro">
<h4>Report prepared for <?php echo $_POST['name']; ?></h4>
Session completed on <?php echo $today; ?>.
<div class="info">
Thanks for using the online Projective Differential scorer, <?php echo $_POST['name']; ?>.</div>
<div class="section" id="epitomizing">
<h3>Epitomizing Picture Scores</h3>
<div class="info">The graphs below show how many times each image was chosen for each topic, as a percentage of the number of times the image was displayed for the topic.</div>
<div class="info">Which picture did you choose the most for each topic? Which did you choose the least? In what ways is the "epitomizing" picture like the topic? In what ways is the "antithetical" image different from the topic?</div>
<?php
//SET THE TEXT FOR THE EPITOMIZING & ANTITHETICAL PICTURES AREA FOR ALL CHARTS
$image_a = '<div class="epitimage"><span class="img"><img src="images/PDImages/image_a.png" width="150px"></span> Image A was the';
$image_b = '<div class="epitimage"><span class="img"><img src="images/PDImages/image_b.png" width="150px"></span> Image B was the';
$image_c = '<div class="epitimage"><span class="img"><img src="images/PDImages/image_c.png" width="150px"></span> Image C was the';
$image_d = '<div class="epitimage"><span class="img"><img src="images/PDImages/image_d.png" width="150px"></span> Image D was the';
$image_e = '<div class="epitimage"><span class="img"><img src="images/PDImages/image_e.png" width="150px"></span> Image E was the';
$epit_text = 'Epitomizing Picture';
$anti_text = 'Antithetical Picture';
$presented = '% of the times it was presented.<br />';
$descrip_a = 'Your description of Image A was:<blockquote>'.$_POST['desc_a'].'</blockquote>In what ways is "';
$descrip_b = 'Your description of Image B was:<blockquote>'.$_POST['desc_b'].'</blockquote>In what ways is "';
$descrip_c = 'Your description of Image C was:<blockquote>'.$_POST['desc_c'].'</blockquote>In what ways is "';
$descrip_d = 'Your description of Image D was:<blockquote>'.$_POST['desc_d'].'</blockquote>In what ways is "';
$descrip_e = 'Your description of Image E was:<blockquote>'.$_POST['desc_e'].'</blockquote>In what ways is "';
//get the topics
$topic = array($_POST['topic1'],$_POST['topic2'],$_POST['topic3'],$_POST['topic4'],$_POST['topic5']);
//get the raw data for each choice
$ab = array($_POST['ab1'],$_POST['ab2'],$_POST['ab3'],$_POST['ab4'],$_POST['ab5']);
$cd = array($_POST['cd1'],$_POST['cd2'],$_POST['cd3'],$_POST['cd4'],$_POST['cd5']);
$ae = array($_POST['ae1'],$_POST['ae2'],$_POST['ae3'],$_POST['ae4'],$_POST['ae5']);
$bd = array($_POST['bd1'],$_POST['bd2'],$_POST['bd3'],$_POST['bd4'],$_POST['bd5']);
$ec = array($_POST['ec1'],$_POST['ec2'],$_POST['ec3'],$_POST['ec4'],$_POST['ec5']);
$da = array($_POST['da1'],$_POST['da2'],$_POST['da3'],$_POST['da4'],$_POST['da5']);
$eb = array($_POST['eb1'],$_POST['eb2'],$_POST['eb3'],$_POST['eb4'],$_POST['eb5']);
$ca = array($_POST['ca1'],$_POST['ca2'],$_POST['ca3'],$_POST['ca4'],$_POST['ca5']);
$de = array($_POST['de1'],$_POST['de2'],$_POST['de3'],$_POST['de4'],$_POST['de5']);
$bc = array($_POST['bc1'],$_POST['bc2'],$_POST['bc3'],$_POST['bc4'],$_POST['bc5']);
//start looping - need to loop 5 times to get through the 5 topics
for($i=0; $i<=4; $i++){
//GENERATE PICTURE COUNTS
//get count for image a
$ia[$i] = 0;
if($ab[$i] == 1){
$ia[$i] = $ia[$i] + 1;
}
if($ae[$i] == 1){
$ia[$i] = $ia[$i] + 1;
}
if($da[$i] == 2){
$ia[$i] = $ia[$i] + 1;
}
if($ca[$i] == 2){
$ia[$i] = $ia[$i] + 1;
}
//get count of image b
$ib[$i] = 0;
if($ab[$i] == 2){
$ib[$i] = $ib[$i] + 1;
}
if($bd[$i] == 1){
$ib[$i] = $ib[$i] + 1;
}
if($eb[$i] == 2){
$ib[$i] = $ib[$i] + 1;
}
if($bc[$i] == 1){
$ib[$i] = $ib[$i] + 1;
}
//get count of image c
$ic[$i] = 0;
if($cd[$i] == 1){
$ic[$i] = $ic[$i] + 1;
}
if($ec[$i] == 2){
$ic[$i] = $ic[$i] + 1;
}
if($ca[$i] == 1){
$ic[$i] = $ic[$i]+ 1;
}
if($bc[$i] == 2){
$ic[$i] = $ic[$i] + 1;
}
//get count of image d
$id[$i] = 0;
if($cd[$i] == 2){
$id[$i] = $id[$i] + 1;
}
if($bd[$i] == 2){
$id[$i] = $id[$i] + 1;
}
if($da[$i] == 1){
$id[$i] = $id[$i] + 1;
}
if($de[$i] == 1){
$id[$i] = $id[$i] + 1;
}
//get count of image e
$ie[$i] = 0;
if($ae[$i] == 2){
$ie[$i] = $ie[$i] + 1;
}
if($ec[$i] == 1){
$ie[$i] = $ie[$i] + 1;
}
if($eb[$i] == 1){
$ie[$i] = $ie[$i] + 1;
}
if($de[$i] == 2){
$ie[$i] = $ie[$i] + 1;
}
//FIND OUT WHICH PICTURE(S) WERE CHOSEN THE MOST OFTEN (EPITOMIZING) FOR EACH TOPIC
$epitomizing[$i] = max(array($ia[$i] / 4 * 100,$ib[$i] / 4 * 100,$ic[$i] / 4 * 100,$id[$i] / 4 * 100,$ie[$i] / 4 * 100));
//FIND OUT WHICH PICTURE(S) WERE CHOSEN THE LEAST OFTEN (ANTITHETICAL) FOR EACH TOPIC
$antithetical[$i] = min(array($ia[$i] / 4 * 100,$ib[$i] / 4 * 100,$ic[$i] / 4 * 100,$id[$i] / 4 * 100,$ie[$i] / 4 * 100));
if($epitomizing[$i] == $ia[$i] / 4 * 100){
$hover_a[$i] = "Epitomizing picture chosen";
} elseif($antithetical[$i] == $ia[$i] / 4 * 100) {
$hover_a[$i] = "Antithetical picture chosen";
} else {
$hover_a[$i] = "Neither empitomizing nor antithetical";
}
if($epitomizing[$i] == $ib[$i] / 4 * 100){
$hover_b[$i] = "Epitomizing picture chosen";
} elseif($antithetical[$i] == $ib[$i] / 4 * 100) {
$hover_b[$i] = "Antithetical picture chosen";
} else {
$hover_b[$i] = "Neither empitomizing nor antithetical";
}
if($epitomizing[$i] == $ic[$i] / 4 * 100){
$hover_c[$i] = "Epitomizing picture chosen";
} elseif($antithetical[$i] == $ic[$i] / 4 * 100) {
$hover_c[$i] = "Antithetical picture chosen";
} else {
$hover_c[$i] = "Neither empitomizing nor antithetical";
}
if($epitomizing[$i] == $id[$i] / 4 * 100){
$hover_d[$i] = "Epitomizing picture chosen";
} elseif($antithetical[$i] == $id[$i] / 4 * 100) {
$hover_d[$i] = "Antithetical picture chosen";
} else {
$hover_d[$i] = "Neither empitomizing nor antithetical";
}
if($epitomizing[$i] == $ie[$i] / 4 * 100){
$hover_e[$i] = "Epitomizing picture chosen";
} elseif($antithetical[$i] == $ie[$i] / 4 * 100) {
$hover_e[$i] = "Antithetical picture chosen";
} else {
$hover_e[$i] = "Neither empitomizing nor antithetical";
}
//create Column3D chart
$EPIT[$i] = new FusionCharts("Column3D","600","400");
//set the relative path for the swf
$EPIT[$i]->setSWFPath("FCharts/FusionCharts/");
//set chart attributes
$strParam="caption=Epitomizing Picture for ".$topic[$i].";yAxisName=%25 times chosen;yAxisMinValue=0;yAxisMaxValue=100;decimalPrecision=0;formatNumberScale=5;numberSuffix=%25;numdivlines=3;canvasBgColor=eeeeee;canvasBaseColor=eeeeee";
$EPIT[$i]->setChartParams($strParam);
//add chart values
$EPIT[$i]->addChartData($ia[$i] / 4 * 100,"name=Image A;alpha=75;hoverText=".$hover_a[$i]);
$EPIT[$i]->addChartData($ib[$i] / 4 * 100,"name=Image B;alpha=75;hoverText=".$hover_b[$i]);
$EPIT[$i]->addChartData($ic[$i] / 4 * 100,"name=Image C;alpha=75;hoverText=".$hover_c[$i]);
$EPIT[$i]->addChartData($id[$i] / 4 * 100,"name=Image D;alpha=75;hoverText=".$hover_d[$i]);
$EPIT[$i]->addChartData($ie[$i] / 4 * 100,"name=Image E;alpha=75;hoverText=".$hover_e[$i]);
echo '<div class="chart">';
$EPIT[$i]->renderChart();
echo '<br />';
echo '<div class="charttxt">';
//GET EPITOMIZING IMAGE(S) & DESCRIPTIONS
if($epitomizing[$i] == $ia[$i] / 4 * 100){
echo $image_a.''.$epit_text.' for '.$topic[$i].', chosen '.$epitomizing[$i].$presented.' '.$descrip_a.$topic[$i].'" like that?</div>';
}
if($epitomizing[$i] == $ib[$i] / 4 * 100){
echo $image_b.' '.$epit_text.' for '.$topic[$i].', chosen '.$epitomizing[$i].$presented.' '.$descrip_b.$topic[$i].'" like that?</div>';
}
if($epitomizing[$i] == $ic[$i] / 4 * 100){
echo $image_c.' '.$epit_text.' for '.$topic[$i].', chosen '.$epitomizing[$i].$presented.' '.$descrip_c.$topic[$i].'" like that?</div>';
}
if($epitomizing[$i] == $id[$i] / 4 * 100){
echo $image_d.' '.$epit_text.' for '.$topic[$i].', chosen '.$epitomizing[$i].$presented.' '.$descrip_d.$topic[$i].'" like that?</div>';
}
if($epitomizing[$i] == $ie[$i] / 4 * 100){
echo $image_e.' '.$epit_text.' for '.$topic[$i].', chosen '.$epitomizing[$i].$presented.' '.$descrip_e.$topic[$i].'" like that?</div>';
}
//GET ANTITHETICAL IMAGE(S) & DESCRIPTIONS
if($antithetical[$i] == $ia[$i] / 4 * 100){
echo $image_a.' '.$anti_text.' for '.$topic[$i].', chosen '.$antithetical[$i].$presented.' '.$descrip_a.$topic[$i].'" not like that?</div>';
}
if($antithetical[$i] == $ib[$i] / 4 * 100){
echo $image_b.' '.$anti_text.' for '.$topic[$i].', chosen '.$antithetical[$i].$presented.' '.$descrip_b.$topic[$i].'" not like that?</div>';
}
if($antithetical[$i] == $ic[$i] / 4 * 100){
echo $image_c.' '.$anti_text.' for '.$topic[$i].', chosen '.$antithetical[$i].$presented.' '.$descrip_c.$topic[$i].'" not like that?</div>';
}
if($antithetical[$i] == $id[$i] / 4 * 100){
echo $image_d.' '.$anti_text.' for '.$topic[$i].', chosen '.$antithetical[$i].$presented.' '.$descrip_d.$topic[$i].'" not like that?</div>';
}
if($antithetical[$i] == $ie[$i] / 4 * 100){
echo $image_e.' '.$anti_text.' for '.$topic[$i].', chosen '.$antithetical[$i].$presented.' '.$descrip_e.$topic[$i].'" not like that?</div>';
}
echo "</div></div>";
} //return to top to loop and recreate for each topic
?>
This produces 5 charts (1 per topic) showing how often each image was chosen as a percentage of the times it was presented for a topic (each image is presented 4 times per topic). It also tells us which image(s) was/were "epitomizing" and "antithetical" for each topic, and provides a copy of those images and the descriptions provided by the respondent on the form.
I'll keep looking over the code you provided to see if I can figure it out.

Since I'll be making a couple more of these, including some that draw the same data from a database, it's probably good that I figure out how to do it the "right" (or best/easiest/most efficient) way.
Thanks,
Scott