doucettej3 Posted November 25, 2008 Share Posted November 25, 2008 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 More sharing options...
sasa Posted November 25, 2008 Share Posted November 25, 2008 what is output of your script? Link to comment https://forums.phpfreaks.com/topic/134209-output-error/#findComment-698593 Share on other sites More sharing options...
doucettej3 Posted November 25, 2008 Author Share Posted November 25, 2008 I want it to output what week is closest to their favorite temp Link to comment https://forums.phpfreaks.com/topic/134209-output-error/#findComment-698631 Share on other sites More sharing options...
sasa Posted November 25, 2008 Share Posted November 25, 2008 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 More sharing options...
doucettej3 Posted November 25, 2008 Author Share Posted November 25, 2008 That just makes it say the ideal week is 0. So that doesnt work Link to comment https://forums.phpfreaks.com/topic/134209-output-error/#findComment-698771 Share on other sites More sharing options...
Maq Posted November 25, 2008 Share Posted November 25, 2008 Where are create_array() and avg() defined? functions.php? Can you post these functions? Link to comment https://forums.phpfreaks.com/topic/134209-output-error/#findComment-698800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.