Hello
I've coded a poll in php and it is putting the form submission values in the database. BUT it isn't showing the results. Here is my code to show the results. I've got some debugging in here and it is printing the answer totals but not showing the results -- I think the problem area is @mysql_data_seek($results, $new);
/*Function showResults($pollId,$db_name,$table_Answers,$table_Questions,$recentPollId) - This will display the totals of the results */
function showResults($pollId,$db_name,$table_Answers,$table_Questions,$recentPollId) {
//First thing is to perform an inner join to get the answers and answer values from both tables
//connect to database and poll table so can get the question that is currently active
$connection = mysql_connect("mysql14.ixwebhosting.com","dkyles_dba", "finance") or die ("Couldn't connect.");
//variable to hold result db selection
$db = mysql_select_db($db_name, $connection) or die("Couldn't select database.");
//echo 'Call sql statement';
//Form sql statement
$sql = "SELECT * FROM $table_Questions pq ";
$sql .= "INNER JOIN $table_Answers pa ON pq.pollID = pa.pollID ";
$sql .= "WHERE pq.pollID = \"$recentPollId\"";
//first see if there are any answer in the table or not
//run query
$results = mysql_query($sql, $connection) or die ("Couldn't execute query. Check for answers". mysql_error());
//echo '<BR> Called sql statement - with sql statement '. $sql .'And the results is '.$results;
//get number of results
$num_results = mysql_num_rows($results);
//echo '<BR>Number of results is ' .$num_results;
//NOW if there is a num of results then perform the following else state there are currently no results
if ($num_results == 0) {
//display no results at the present time
echo '
<BR><BR>
There are currently no results in the system.';
}
else {
//echo 'Initialize answers';
//Initialize each answer into a multi-dimensional array and answerTotal
$answertally[0] = 0;
$answertally[1] = 0;
$answertally[2] = 0;
$answertally[3] = 0;
$answertally[4] = 0;
$answerTotal = 0;
//Now loop through the results gotten and
while($pRow = mysql_fetch_array($results))
{
//echo '<BR> In while loop';
/*echo '<BR> Here are the values being checked:
<BR> pRow[answer] = '.$pRow["answer"].'
<BR> pRow[answer1] = '.$pRow["answer1"].'
<BR> pRow[answer2] = '.$pRow["answer2"].'
<BR> pRow[answer3] = '.$pRow["answer3"].'
<BR> pRow[answer4] = '.$pRow["answer4"].'
<BR> pRow[answer5] = '.$pRow["answer5"];*/
switch($pRow["answer"])
{
case $pRow["answer1"]:
$answertally[0]++;
//echo 'Answer 1 tally ' . $answertally[0];
break;
case $pRow["answer2"]:
$answertally[1]++;
//echo 'Answer 2 tally ' . $answertally[1];
break;
case $pRow["answer3"]:
$answertally[2]++;
//echo 'Answer 3 tally ' . $answertally[2];
break;
case $pRow["answer4"]:
$answertally[3]++;
//echo 'Answer 4tally ' . $answertally[3];
break;
case $pRow["answer5"]:
$answertally[4]++;
//echo 'Answer 5 tally ' . $answertally[4];
break;
}
}
echo '<BR>Out of while loop';
// Get the total number of votes
for($i = 0; $i < sizeof($answertally); $i++)
$answertotal += $answertally[$i];
$new = 0;
//echo '<BR> Got the answertotal which is '.$answertotal;
//echo $pRow["question"];
//echo 'Did it show the question';
@mysql_data_seek($results, $new);
//Now display the information for the results
//First display the question
//echo $pRow["question"];
echo '<BR><BR>';
for($i = 1; $i <= 5; $i++) {
echo 'The item looking for is '. $pRow["answer$i"];
if($pRow["answer$i"] != "")
{
echo 'The row answer is '.$pRow["answer$i"];
} //end IF
} //end For
}// end else
} //end show function
Any guidance is most appreciated.
Thanks!
I've coded a poll in php and it is putting the form submission values in the database. BUT it isn't showing the results. Here is my code to show the results. I've got some debugging in here and it is printing the answer totals but not showing the results -- I think the problem area is @mysql_data_seek($results, $new);
/*Function showResults($pollId,$db_name,$table_Answers,$table_Questions,$recentPollId) - This will display the totals of the results */
function showResults($pollId,$db_name,$table_Answers,$table_Questions,$recentPollId) {
//First thing is to perform an inner join to get the answers and answer values from both tables
//connect to database and poll table so can get the question that is currently active
$connection = mysql_connect("mysql14.ixwebhosting.com","dkyles_dba", "finance") or die ("Couldn't connect.");
//variable to hold result db selection
$db = mysql_select_db($db_name, $connection) or die("Couldn't select database.");
//echo 'Call sql statement';
//Form sql statement
$sql = "SELECT * FROM $table_Questions pq ";
$sql .= "INNER JOIN $table_Answers pa ON pq.pollID = pa.pollID ";
$sql .= "WHERE pq.pollID = \"$recentPollId\"";
//first see if there are any answer in the table or not
//run query
$results = mysql_query($sql, $connection) or die ("Couldn't execute query. Check for answers". mysql_error());
//echo '<BR> Called sql statement - with sql statement '. $sql .'And the results is '.$results;
//get number of results
$num_results = mysql_num_rows($results);
//echo '<BR>Number of results is ' .$num_results;
//NOW if there is a num of results then perform the following else state there are currently no results
if ($num_results == 0) {
//display no results at the present time
echo '
<BR><BR>
There are currently no results in the system.';
}
else {
//echo 'Initialize answers';
//Initialize each answer into a multi-dimensional array and answerTotal
$answertally[0] = 0;
$answertally[1] = 0;
$answertally[2] = 0;
$answertally[3] = 0;
$answertally[4] = 0;
$answerTotal = 0;
//Now loop through the results gotten and
while($pRow = mysql_fetch_array($results))
{
//echo '<BR> In while loop';
/*echo '<BR> Here are the values being checked:
<BR> pRow[answer] = '.$pRow["answer"].'
<BR> pRow[answer1] = '.$pRow["answer1"].'
<BR> pRow[answer2] = '.$pRow["answer2"].'
<BR> pRow[answer3] = '.$pRow["answer3"].'
<BR> pRow[answer4] = '.$pRow["answer4"].'
<BR> pRow[answer5] = '.$pRow["answer5"];*/
switch($pRow["answer"])
{
case $pRow["answer1"]:
$answertally[0]++;
//echo 'Answer 1 tally ' . $answertally[0];
break;
case $pRow["answer2"]:
$answertally[1]++;
//echo 'Answer 2 tally ' . $answertally[1];
break;
case $pRow["answer3"]:
$answertally[2]++;
//echo 'Answer 3 tally ' . $answertally[2];
break;
case $pRow["answer4"]:
$answertally[3]++;
//echo 'Answer 4tally ' . $answertally[3];
break;
case $pRow["answer5"]:
$answertally[4]++;
//echo 'Answer 5 tally ' . $answertally[4];
break;
}
}
echo '<BR>Out of while loop';
// Get the total number of votes
for($i = 0; $i < sizeof($answertally); $i++)
$answertotal += $answertally[$i];
$new = 0;
//echo '<BR> Got the answertotal which is '.$answertotal;
//echo $pRow["question"];
//echo 'Did it show the question';
@mysql_data_seek($results, $new);
//Now display the information for the results
//First display the question
//echo $pRow["question"];
echo '<BR><BR>';
for($i = 1; $i <= 5; $i++) {
echo 'The item looking for is '. $pRow["answer$i"];
if($pRow["answer$i"] != "")
{
echo 'The row answer is '.$pRow["answer$i"];
} //end IF
} //end For
}// end else
} //end show function
Any guidance is most appreciated.
Thanks!