Jump to content

Output error


doucettej3

Recommended Posts

I cant get this code to output. I think theres something wrong with the variable $fav_temp but i cant figure out what.

This is the function its used in:

function vac_week($avg_array, $fav_temp)
{ 
$low = $fav_temp - 10;
$high = $fav_temp + 10;

for($k = 0; $k < 52; $k++)
{	
if($avg_array[$k] >= $low && $avg_array[$k] <= $high)
{
	echo 'Your Ideal vacation week is week ' . $k;
	}
	else
	{
	echo "noMatches";
	}



}
}

And This is the switch:

$action = $_GET['action'];
require('functions.php');
switch($action)
{
case 'generate':
$fav_temp = $_GET[‘fav_temp’];
$random_array = create_array(); 
$average = avg($random_array); 
$vacation = vac_week($avg_array, $fav_temp);

break;
default:
  ?>
  <table align="center">
  <form name="settingsFORM" action="index.php" METHOD=GET>
  <input type=HIDDEN name="action" value="generate">
  <tr><th colspan=2>Settings
  <tr><td>Favorite Temperature: <input type=TEXT name="fav_temp" size=1>
  <tr><td><input type=SUBMIT value="Continue >>">
  </form>
  </table>
  <?php
break;
}

Link to comment
https://forums.phpfreaks.com/topic/134209-output-error/
Share on other sites

try

function vac_week($avg_array, $fav_temp)
{
$min = 10000;
$out = 10000;  
   for($k = 0; $k < 52; $k++) if(abs($avg_array[$k] - $fav_temp) < $min) {
        $out = $k;
        $min =  abs($avg_array[$k] - $fav_temp);
   }
   echo 'Your Ideal vacation week is week ' . $out;
}

Link to comment
https://forums.phpfreaks.com/topic/134209-output-error/#findComment-698646
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.