Output error

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 1515 Views - Last Post: 25 November 2008 - 07:01 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

Post icon  Posted 24 November 2008 - 07:18 PM

This code doesnt output at all. I cant figure out whats wrong with it. any help would be greatly appreciated.
function vac_week($avg_array, $fav_temp)
{ 
	
	$k = 0;
	while($k < 52)
{
	if($avg_array[$k] <= ($fav_temp + 10) && $avg_array[$k] >= ($fav_temp - 10))
	{
		echo 'Your Ideal vacation week is week ' . $k;
		
		}
		else
		{
		$k++;
		}
		}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Output error

#2 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Re: Output error

Posted 24 November 2008 - 07:44 PM

Can I see the rest of the code, such as:

$avg_array computation
$fav_temp computation

I don't see anything clearly wrong but just because this bit of code is what echo's your information, doesn't mean the problem is here.

If your variables are messed up, this script wont execute.
Was This Post Helpful? 0
  • +
  • -

#3 doucettej3  Icon User is offline

  • New D.I.C Head

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

Re: Output error

Posted 24 November 2008 - 07:50 PM

I use a switch as well idk if u want that, This is my functions file.
<?php
function create_array()
{
//create the array
	$random_numbers = array();
	for($j = 0; $j < 52; $j++)
	{
	for($i = 0; $i < 7; $i++)
	{
	  $random_numbers[$j][$i] = rand(0, 100);
	}
	}
	//print out the array
   
	
	//return the array to the program
	return $random_numbers;
	
}
  


function avg($random_numbers)
{
$avg_array = array();
$j = 0;
while($j < 52)
{
for($k = 0; $k < 52; $k++)
{ $sum = 0;
for($i = 0; $i < 7; $i++)  
{
$sum = $sum + $random_numbers[$j][$i];
}
$avg = ($sum / 7);
$avg_array[$k] = $avg;
$j++;
} 
}
print_r($avg_array);
return $avg_array;
}

function vac_week($avg_array, $fav_temp)
{ 
	
	$k = 0;
	while($k < 52)
{
	if($avg_array[$k] <= ($fav_temp + 10) && $avg_array[$k] >= ($fav_temp - 10))
	{
		echo 'Your Ideal vacation week is week ' . $k;
		
		}
		else
		{
		$k++;
		}
		}
		
		
	


}


Was This Post Helpful? 0
  • +
  • -

#4 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Re: Output error

Posted 24 November 2008 - 07:54 PM

I hate nesting statements... I'm going to re-write your code a bit, tell me if it works.

I'm not going to test it, but either way it should work... just let me know if it doesn't.


**Will edit when code done**
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

Posted 24 November 2008 - 07:56 PM

thanks, you are now my hero.
Was This Post Helpful? 0
  • +
  • -

#6 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Re: Output error

Posted 24 November 2008 - 08:07 PM

I'm working on it but from the code you've given me I still don't see where $fav_temp is being identified.

I'll continue working, but if theres a possible syntax error then I need to know ALL of the code we are working with.

Update me, I'm sitting right here re-writing what you've gotten to clean up the code a bit!

This post has been edited by pr4y: 24 November 2008 - 08:07 PM

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

Posted 24 November 2008 - 08:09 PM

The user inputs their fav temp and its stored as fav temp in 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;
}


Was This Post Helpful? 0
  • +
  • -

#8 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Re: Output error

Posted 24 November 2008 - 08:17 PM

I honestly didn't see too much wrong with the script, but I did rewrite it as if I were writing the same functions... and here is what I ended up with:

<?php

function makethearray()
{

$random_numbers = array();
$j=0;
$i=0;
while($j < 52){
	while($i < 7){
		$random_numbers[$j][$i] = rand(0,100);
		$j++;
		$i++;
		}
	}
	return $random_numbers;	
}

function randavg($random_numbers)
{

$avg_array = array();
$j=0;
$k=0;
$i=0;

while($j < 52){
	if($k < 52){
		$sum = 0;
		$k++;
	} else {
		if($i < 7){
			$sum = $sum + $random_numbers[$j][$i];
		}
		$avg = ($sum / 7);
		$avg_array[$k] = $avg;
		$j++;
	}
	print_r($avg_array);
	return $avg_array;
}

function vac_week($avg_array, $fav_temp)
{  
$k = 0;
while($k < 52){
    if($avg_array[$k] <= ($fav_temp + 10) && $avg_array[$k] >= ($fav_temp - 10)){
    	echo 'Your Ideal vacation week is week ' . $k;  
        } else {
        	$k++;
        	}
        }
}




Let me know if it works... I could have mistakes :P I'm just bored so I decided to rewrite it and maybe it'll fix the problems your having.

This post has been edited by pr4y: 24 November 2008 - 08:21 PM

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

Posted 24 November 2008 - 08:30 PM

It came up with an error. Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\lab 10\functions.php on line 17
Im lookin into that now

I think for loops might work better in this function
function makethearray()  
{  
  
$random_numbers = array();  
$j=0;  
$i=0;  
while($j < 52){  
	while($i < 7){  
		$random_numbers[$j][$i] = rand(0,100);  
		$j++;  
		$i++;  
		}  
	}  
	return $random_numbers;   
}  


Was This Post Helpful? 0
  • +
  • -

#10 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Output error

Posted 24 November 2008 - 08:33 PM

View Postdoucettej3, on 24 Nov, 2008 - 10:30 PM, said:

It came up with an error. Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\lab 10\functions.php on line 17
Im lookin into that now


PHP.ini.

max_execution_time.

Raise it past 30 to whatever you need the max execution time to be :)

This post has been edited by Valek: 24 November 2008 - 08:33 PM

Was This Post Helpful? 0
  • +
  • -

#11 doucettej3  Icon User is offline

  • New D.I.C Head

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

Re: Output error

Posted 24 November 2008 - 08:35 PM

how do i raise the execution time
Was This Post Helpful? 0
  • +
  • -

#12 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Re: Output error

Posted 24 November 2008 - 08:35 PM

ewwwww windows hosted wamp box :X


I've had more compatibility issues with WAMP than any other platform I've ever worked with. Not sure why... but I have extreme hatred for it.

</offtopic>


are you running this locally or is it a windows hosting package?
Was This Post Helpful? 0
  • +
  • -

#13 doucettej3  Icon User is offline

  • New D.I.C Head

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

Re: Output error

Posted 24 November 2008 - 08:36 PM

Im using local host
Was This Post Helpful? 0
  • +
  • -

#14 doucettej3  Icon User is offline

  • New D.I.C Head

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

Re: Output error

Posted 24 November 2008 - 08:46 PM

Changing max execution time still doesnt work
Was This Post Helpful? 0
  • +
  • -

#15 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Re: Output error

Posted 24 November 2008 - 08:47 PM

Have you updated your PHP.ini and tested this yet?

ok, so what is the error? Timeout?

can you copy + paste your PHP.ini here?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2