Table Driving Me Crazy!!!!!!

I have everything with my table working correctly EXCEPT one row of the table is not working.

The row that says: Do you think Liverpool can win the League this year? is not working like the other rows. All the other rows show the number of yes answers and the % but this row does not work like those (I get a box that isn’t a box for the table, no number of yes answers and no % for this row).

Here is my php code:

[php]

Liverpool Survey
<?php
	
 	$watchEPL = 0;
 	$liverpoolFan = 0;
 	$winners = 0;
 	$count = 0;
 	
 	$surveyFile = fopen("liverpoolSurvey.txt", "r");
 	$nextSurvey = fgets($surveyFile);
 	
 	print("<h1>Liverpool Survey Results</h1>");
 	print ("<table border = \"1\"> ");
 	print("<tr><th>QUESTION</th><th>COUNT</th><th>PERCENTAGE</th></tr>");
 	
  while(!feof($surveyFile))
 {
 		list($watchEPL, $liverpoolFan, $winners) = 
 		explode(":",$nextSurvey);
		$count = $count + 1;
		
 if($watchEPL == "Yes")
 {
 		$totalWatchEPL = $totalWatchEPL + 1;
 		
 }
 if($liverpoolFan == "Yes")
 {
 		$totalLiverpoolFan = $totalLiverpoolFan + 1;
 }
if($winners == "yes")
{
 		$totalWinners = $totalWinners + 1;
}
 $nextSurvey = fgets($surveyFile);
 }
  fclose($surveyFile);
  
  $percentSurvery = ($count/$count) * 100;
  $percentWatchEPL = ($totalWatchEPL/$count) * 100;
  $percentLiverpoolFan = ($totalLiverpoolFan/$count) * 100;
  $percentTotalWinners = ($winners/$count) * 100;
  
  	print("<tr><td>Do you watch English Premier League football?</td>
		   <td>$totalWatchEPL</td>
		   <td>".number_format($percentWatchEPL,2)."%</td></tr>");
	print("<tr><td>Are you a Liverpool fan?</td>
			<td>$totalLiverpoolFan</td>
			<td>".number_format($percentLiverpoolFan,2)."%</td></tr>");
	print("<tr><td>Do you think Liverpool can win the League this year?</td>
			<td>$totalWinners</td>
			<td>".number_format($percentTotalWinners,2)."%</td></tr>");
	print("<tr><td>TOTAL NUMBER OF SURVEYS RECEIVED</td><td>$count</td>
			<td>".number_format($percentSurvery,2)."%</td></tr>");
 	print("</table>");


?>
	
	
<p><a href = "projectSurvey.html">Return to the Liverpool Survey form</a></p> 
[/php]

Thanks a lot for your help. You guys have been a life saver several times :slight_smile:

Jason

Is it possible to post or message me the contents of liverpoolSurvey.txt so I can test it out?

I can do that, just tell me what email address to send it to.

Jason

Hi there,

For the ‘liverpool being the winners’, this statement is different:
[php] if($winners == “yes”)[/php]

The others are “Yes” - is the answer for winners in your file actually stored differently, or will changing this to “Yes” partially fix your issue?

Still doesn’t work.

Hey,

See fixed code (have put comments in places I have added/edited something):
[php]

<?php $watchEPL = 0; $liverpoolFan = 0; $winners = 0; $count = 0; $totalWinners = 0; //Initiate variable as integer for addition (won't matter on some servers, but better to be safe than sorry) $surveyFile = fopen("liverpoolSurvey.txt", "r"); $nextSurvey = fgets($surveyFile); print("

Liverpool Survey Results

"); print(" "); print(""); while(!feof($surveyFile)) { list($watchEPL, $liverpoolFan, $winners) = explode(":",$nextSurvey); $count = $count + 1; if($watchEPL == "Yes") { $totalWatchEPL = $totalWatchEPL + 1; } if($liverpoolFan == "Yes") { $totalLiverpoolFan = $totalLiverpoolFan + 1; } if(trim($winners) == "Yes") //Added trim() to variable (can add to others if you wish) - it was probably including newline character { $totalWinners++; } $nextSurvey = fgets($surveyFile); } fclose($surveyFile); $percentSurvery = ($count/$count) * 100; $percentWatchEPL = ($totalWatchEPL/$count) * 100; $percentLiverpoolFan = ($totalLiverpoolFan/$count) * 100; $percentTotalWinners = ($totalWinners/$count) * 100; //variable $winners replaced with $totalWinners print(""); print(""); print(''); print(""); print("
QUESTION COUNT PERCENTAGE
Do you watch English Premier League football? $totalWatchEPL ".number_format($percentWatchEPL,2)."%
Are you a Liverpool fan? $totalLiverpoolFan ".number_format($percentLiverpoolFan,2)."%
Do you think Liverpool can win the League this year? '.$totalWinners.' '.number_format($percentTotalWinners,2).'%
TOTAL NUMBER OF SURVEYS RECEIVED $count ".number_format($percentSurvery,2)."%
"); ?>[/php]

Should be that all sorted!

Sponsor our Newsletter | Privacy Policy | Terms of Service