I've been having a difficult time understanding the proper way to do this.
I have a DB that contains information. I want to be able to pull the information from the database, manipulate and display it. I'm getting a parsing error with the following function:
function tally_value($question){
global $sumA[$question],$sumB[$question],$sumC[$question];
global $sumD[$question],$sumE[$question];
switch($question) {
case $question=1:
$sumA[$question]++;
break;
case $question=2:
$sumB[$question]++;
break;
case $question=3:
$sumC[$question]++;
break;
case $question=4:
$sumD[$question]++;
break;
case $question=5:
$sumE[$question]++;
break;
};
};
#the function is to be used in the following way.
$query_result_handle = mysql_query("SELECT a1,a2,a3,a4,a5,a6,a7 FROM srvd WHERE id=$record_id",$link_id);
$num_of_records = mysql_num_rows ($query_result_handle) or die ("The query: '$query' did not return any data");
for ($count = 1; $row = mysql_fetch_array ($query_result_handle); ++$count) {
IF( isset ($row[a1])) {
$completed_surveys++;
print "<b>Fetching row # ".$count." from the query.</b><br>";
tally_value($row[a1]);
tally_value($row[a2]);
tally_value($row[a3]);
tally_value($row[a4]);
tally_value($row[a5]);
tally_value($row[a6]);
tally_value($row[a7]);
};
};
$average_result=( 1$sumA[a1]+2$sumB[a1]+3$sumC[a1]+4$sumD[a1]+5*$sumE[a1])/$completed_surveys;
echo "The average for all submitted answers to this question was ".$average_result."<br>";
I need to have these values be persistant because I reference them repeatedly in in the program.
The concept that I am having trouble grasping is understanding how to properly deal with arrays and how to expand their scope. I'm trying to minimize the # of queries to speed up the program.
I need to keep the arrays linked to the specific result that I pull from the DB. What is the best way of creating an associative array when you don't know what the index will be?
Maybe there is a better way to accomplish this goal.
I also seem to be having a difficult time making these arrays global in scope. There must be a way of doing this. Help me to understand please.
Thank you,
Bryan