9 Replies - 734 Views - Last Post: 25 November 2008 - 11:48 AM Rate Topic: -----

#1 doucettej3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 22-October 08

Output error Redux

Post icon  Posted 25 November 2008 - 07:06 AM

I cant get my function to output at all. I think there could be something wrong with my $fav_temp variable. Can anyone help?
This is the function:
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";
		}
		
	

}
}


This is the switch where i get the $fav_temp variable
$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;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Output error Redux

#2 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: Output error Redux

Posted 25 November 2008 - 08:02 AM

Well, the only obvious problem is that you have this line:
$vacation = vac_week($avg_array, $fav_temp);
Your function doesn't return any value, so if you're trying to use $vacation, it's going to be null.

However, this doesn't account for your statement that you're getting no output at all. Assuming your function gets called at all, it should always output something. My first guess would be that you have an error someplace else in your script. Perhaps your avg() or create_array() functions are bombing out. Crank your error_reporting up to E_ALL and see if you get any error messages.
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,659
  • Joined: 23-August 08

Re: Output error Redux

Posted 25 November 2008 - 08:44 AM

One thing that jumps out at me in the code is the difference in single quotes here:
case 'generate':
$fav_temp = $_GET[‘fav_temp’];

Was This Post Helpful? 1
  • +
  • -

#4 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: Output error Redux

Posted 25 November 2008 - 10:08 AM

View PostJackOfAllTrades, on 25 Nov, 2008 - 09:44 AM, said:

One thing that jumps out at me in the code is the difference in single quotes here:

Good call. Those definitely aren't real single-quotes on that second line. So if those funky quotes are actually in the OP's file, that would explain the problem.
Was This Post Helpful? 0
  • +
  • -

#5 doucettej3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 22-October 08

Re: Output error Redux

Posted 25 November 2008 - 10:24 AM

Yea that was a problem..but not the source of the bigger problem. It still doesnt output the ideal week
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3099
  • View blog
  • Posts: 10,885
  • Joined: 08-August 08

Re: Output error Redux

Posted 25 November 2008 - 10:52 AM

I'd do it a little differently:
<?php
$x=array(40,60,70,75,80,85);
$y=71;
vac_week($x,$y);

function vac_week($avg_array, $fav_temp)
{ 
	$Bestweek = 0;
	$currentdiff= 9999;	
 	for($k = 0; $k < 6; $k++)
		{	
		$diff = abs($fav_temp - $avg_array[$k]);
		if($diff < $currentdiff)
			{
			$Bestweek = $k;
			$currentdiff= $diff;
			}
		}
	echo 'Your ideal vacation week is week number ' . $Bestweek." with an average temperature of ".$avg_array[$Bestweek];
}?>


Was This Post Helpful? 0
  • +
  • -

#7 doucettej3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 22-October 08

Re: Output error Redux

Posted 25 November 2008 - 11:16 AM

avg array is an array of random numbers and fav temp is input by the user at the beginning.
Was This Post Helpful? 0
  • +
  • -

#8 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3099
  • View blog
  • Posts: 10,885
  • Joined: 08-August 08

Re: Output error Redux

Posted 25 November 2008 - 11:32 AM

View Postdoucettej3, on 25 Nov, 2008 - 10:16 AM, said:

avg array is an array of random numbers and fav temp is input by the user at the beginning.

Right. I set up an array of random (or not, it doesn't matter!) numbers and set the user input to be 71 in my example of how to get the function to work.
Was This Post Helpful? 0
  • +
  • -

#9 doucettej3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 22-October 08

Re: Output error Redux

Posted 25 November 2008 - 11:37 AM

Yea the output is : vacation week is week number 0 with an average temperature of
Was This Post Helpful? 0
  • +
  • -

#10 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3099
  • View blog
  • Posts: 10,885
  • Joined: 08-August 08

Re: Output error Redux

Posted 25 November 2008 - 11:48 AM

Huh?
My result is:

Your ideal vacation week is week number 2 with an average temperature of 70


Are you running what I provided, or making changes? If so, what changes?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1