1. your while loop should have {} brackets i can't see where it starts and where it ends. so does PHP. leaving brackets away tells PHP that only the next line is part of the while loop. i don't know if your file has only the three lines ($cust_name, $cust_area, $cust_code) or if more than one customer is in your file and every customer has these three lines. if you only have one customer with these three lines, you don't need the while loop, just leave while(!feof($fp2)) away. if there are multiple customers in the file and every customer has these three lines, you should close the while brackets after the switch but before the return.
2. if($cust_code==$code[$index]) is wrong here. you haven't initilized $index as far as i can see, so you get: if($cust_code==$code[null]) what you want to do is checking the array $code for the content $cust_code and getting the index of that element. so it'd be better to do: $row=array_search($cust_code, $code); so try this:(assuming that you have more than one customer in the file and every customer has the three lines. function inquiry($fp2,$date,$name,$code) { while(!feof($fp2)) { $cust_name=trim(fgets($fp2,12)); $cust_area=trim(fgets($fp2,9)); $cust_code=trim(fgets($fp2,6)); if(in_array($cust_code, $code)) { $row=array_search($cust_code, $code); } switch($cust_area) { case "National": print "national<br>"; printf("%1s %1f", $name[$row], $cust_cost[$row][1]); break; case "East": print"East<br>"; printf("%1s %1f", $name[$row], $cust_cost[$row][2]); break; case "Midwest": print"midwest<br>"; printf("%1s %1f", $name[$row], $cust_cost[$row][3]); break; case "Pacific": print"pacific<br>"; printf("%1s %1f", $name[$row], $cust_cost[$row][4]); break; } } return; } "Tony" <[EMAIL PROTECTED]> schrieb im Newsbeitrag [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > Hello, I'm new to this group and already have a problem (actually the > problem is the reason I found the group). I'm taking a Fundamentals of > Programming class, and they are using PHP to get the message across. I'm > having a lot of trouble passing the values in the first array to the second > array. I included the code (below). If anyone would be so kind as to give me > some advice (I'm NOT looking for someone to write it for me, just some > helpful advice). The data is being read in correctly (for the first array > anyway). The first function works wonderfully, the second function is > supposed to handle customer inqueries, working from the $code/$cust_code > variables. I need to match the numbers in these two arrays, and use switch > on $cust_area to let it know what to print. > > > Thanks > > Tony > +++++++++++++++++ > > <html> > <head> </head> > <body> > <pre> > <?php > > $fp1=fopen("proj10b.dat","r"); > $fp2=fopen("proj10b2.dat","r"); > $date=date("m-d-Y"); > > headers($date); > main($fp1,&$name,&$code); > inquiry($fp2,$date,$name,&$code); > fclose($fp1); > fclose($fp2); > > function headers($date) > { > print"DENTAL FEES BY REGION as of Date: $date<br>"; > print" Printed by: Tony Hall<br>"; > print" <br>"; > print" National > New<br>"; > print"Code - Procedure Median > England Midwest Pacific<br>"; > print" <br>"; > return; > } > > function main($fp1,$name,&$code) > { > for($index=0;$index<43;$index++) > { > $name[$index]=(string)fgets($fp1,42); > $code[$index]=(string)fgets($fp1,6); > $nat_cost[$index][1]=(integer)fgets($fp1,4); > $east_cost[$index][2]=(integer)fgets($fp1,4); > $mid_cost[$index][3]=(integer)fgets($fp1,4); > $pac_cost[$index][4]=(integer)fgets($fp1,4); > printf("%1s - %10s %10s %10s %10s %10s", $code[$index], > $name[$index], $nat_cost[$index][1], $east_cost[$index][2], > $mid_cost[$index][3], $pac_cost[$index][4]); > print" <br>"; > } > return; > } > > function inquiry($fp2,$date,$name,$code) > { > while(!feof($fp2)) > > $cust_name=trim(fgets($fp2,12)); > $cust_area=trim(fgets($fp2,9)); > $cust_code=trim(fgets($fp2,6)); > > if($cust_code==$code[$index]) > { > $row=$index; > } > > switch($cust_area) > { > case "National": > print "national<br>"; > > printf("%1s %1f", $name[$row], $cust_cost[$row][1]); > break; > > case "East": > print"East<br>"; > > printf("%1s %1f", $name[$row], $cust_cost[$row][2]); > break; > > case "Midwest": > print"midwest<br>"; > > printf("%1s %1f", $name[$row], $cust_cost[$row][3]); > break; > > case "Pacific": > print"pacific<br>"; > > printf("%1s %1f", $name[$row], $cust_cost[$row][4]); > break; > } > > return; > } > > ?> > </pre> > </body> > </html> > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php