CODE GONE CRAZY aka need help please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spag
Forum Newbie
Posts: 5
Joined: Sun Dec 12, 2010 6:18 pm

CODE GONE CRAZY aka need help please

Post by spag »

I need help a php code...i have a text file that contains 5 columns, the first column is the month ( 1 1 1 1 2 2 2 ......) the second column is each day of the month, the third column is the year the , the fourth column is high temperatures and the fifth column in the low temperatues....the problem is that i need to determine how many days of the month the temperate was below 32 and how many days the temperature was above 90 and the output should be three columns wiht hte months the number of days below 32...i also have no code to provide because all my codes that i have tried are dead ended
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: CODE GONE CRAZY aka need help please

Post by Jonah Bron »

Well, I can't do the whole thing for you, but I can get you going. Here's the query you'll need for the first:

Code: Select all

SELECT * FROM mytable WHERE low_temp < 32
And here's your second query

Code: Select all

SELECT * FROM mytable WHERE high_temp > 90
Do you see how it works? Obviously, you need to change the table name and column names to the way they are in your database...

Also:
Forum Rules wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
spag
Forum Newbie
Posts: 5
Joined: Sun Dec 12, 2010 6:18 pm

Re: CODE GONE CRAZY aka need help please

Post by spag »

Using the text file, write a PHP application that will count for each month the
number of days for which the maximum temperature was above 90°F and the minimum temperature
was below 32°F.

the code is:

1 1 35 19
1 2 29 18
1 3 31 15
1 4 35 22
1 5 32 19
1 6 38 23
1 7 42 23

output
mon <32 >90
1 26 0
spag
Forum Newbie
Posts: 5
Joined: Sun Dec 12, 2010 6:18 pm

Re: CODE GONE CRAZY aka need help please

Post by spag »

i have the input and read from codes done
spag
Forum Newbie
Posts: 5
Joined: Sun Dec 12, 2010 6:18 pm

Re: CODE GONE CRAZY aka need help please

Post by spag »

the columns are

store number invoice number amount 1 amount 2
1 1 32 87
1 2 33 45
1 3 14 56
1 4 90 34
1 5 100 45
1 6 33 75
2 1 36 25
2 2 72 35
2 31 92 65
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: CODE GONE CRAZY aka need help please

Post by Jonah Bron »

spag wrote:Using the text file, write a PHP application that will count for each month the
number of days for which the maximum temperature was above 90°F and the minimum temperature
was below 32°F...
Are you asking us to do it for you?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: CODE GONE CRAZY aka need help please

Post by califdon »

It appears that he's asking us to do his school assignment.
spag
Forum Newbie
Posts: 5
Joined: Sun Dec 12, 2010 6:18 pm

Re: CODE GONE CRAZY aka need help please

Post by spag »

no not at all

i just dont know to start

i have this so far

but

Code: Select all

$in=fopen("data.txt",'r');    
$out=fopen("GDD2001.csv",'w'); 
$count1=0;$a1=0;			 
echo " Run <br/>";	  
for ($i=0; $i<366; $i++)
{	fscanf($in,"%u %u %u %f %f %f %f",$m,$d,$y,$h,$l,$rain,$snow);
if ($m =="1")
  {if ($h <32)
		{$a1= 1;}
	else
		{$a1=0;}} 
	
	
echo $m. " ".$d. " ".$h." ".$a1. "<br/>";
 }


fclose($in);  
fclose($out);
and my issue is that i have no clue how to extract the total amount for month one and that when i run it it provides me with all the months in stead of month 1
Last edited by Benjamin on Sun Dec 12, 2010 7:56 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: CODE GONE CRAZY aka need help please

Post by califdon »

It's not my purpose to accuse you of something you're not guilty of, but when I read, "Using the text file, write a PHP application that will ...", it certainly sounds like an assignment. If not from a teacher, then perhaps in a book you're studying. We could probably give you a lot more help if you would explain what you're trying to do. It sounds like two unrelated projects. Why are you using a text file, to begin with? It sounds like the sort of thing that would use a MySQL database, ordinarily. If we understand your situation, we may be able to help you.
Post Reply