RE: [PHP] Re: Parsing file's

2002-06-02 Thread Scott

Ok, this did not work, but I have a new idea.  From the top

1)Read in the csv file, take the first 18 records and insert them into a
temp db.Ie:  $output = array_slice ($fields, 0, 17);

2)Then do a count on the line to see how many records are after 17 and
somehow loop through them 34 at a time.  

It is easy if there is only one set, but I am not sure how to take the
remaining elements in the array and break them out 34 at a time until I
reach the end of the line.  

Help, my head hurts and I have a habit of over thinking :)

-Scott




-Original Message-
From: Mark Heintz PHP Mailing Lists [mailto:[EMAIL PROTECTED]] 
Sent: Friday, May 31, 2002 4:43 PM
To: Scott
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Re: Parsing file's

You may have been heading in the right direction originally with
array_slice...  This is off the top of my head, I don't guaruntee it
will
work...

$start = 34;
$interval = 15;
$max = 303;
// hop across orig. array 15 columns at a time
for($offset = $start;
$offset  $max  isset($array[$offset]);
$offset += $interval){
  // slice off $interval many columns starting at $offset
  $sub_array = array_slice($array, $i, $interval);
  // handle your $interval many key-value pairs
  foreach ($sub_array as $key = $value){
$policyWriter = $quoteKey|$key|$value;
// ...
  }
}


mh.




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: Parsing file's (SOLVED)

2002-06-02 Thread Scott

The next time I stare at something so long I can't think straight remind
me to take a walk and pull out Rasmus' book!  Page 121 array_chunk is my
friend!

Code is ugly, but I am smiling now!   Thank you everyone!

$policy = array_slice ($fields, 18, $lineCount);  
// I am taking the array from position 18 to the end
$chunks = array_chunk ($policy, 34);  
// Using array_chunk I break the array into pieces of 34
foreach ($chunks as $key = $value){
print_r($chunks);
sleep(5);
}
// The sleep is for me to watch it fly by the screen :)

Thanks again everyone.

-Scott



-Original Message-
From: Scott [mailto:[EMAIL PROTECTED]] 
Sent: Sunday, June 02, 2002 4:57 PM
To: 'Mark Heintz PHP Mailing Lists'
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP] Re: Parsing file's

Ok, this did not work, but I have a new idea.  From the top

1)Read in the csv file, take the first 18 records and insert them into a
temp db.Ie:  $output = array_slice ($fields, 0, 17);

2)Then do a count on the line to see how many records are after 17 and
somehow loop through them 34 at a time.  

It is easy if there is only one set, but I am not sure how to take the
remaining elements in the array and break them out 34 at a time until I
reach the end of the line.  

Help, my head hurts and I have a habit of over thinking :)

-Scott




-Original Message-
From: Mark Heintz PHP Mailing Lists [mailto:[EMAIL PROTECTED]] 
Sent: Friday, May 31, 2002 4:43 PM
To: Scott
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Re: Parsing file's

You may have been heading in the right direction originally with
array_slice...  This is off the top of my head, I don't guaruntee it
will
work...

$start = 34;
$interval = 15;
$max = 303;
// hop across orig. array 15 columns at a time
for($offset = $start;
$offset  $max  isset($array[$offset]);
$offset += $interval){
  // slice off $interval many columns starting at $offset
  $sub_array = array_slice($array, $i, $interval);
  // handle your $interval many key-value pairs
  foreach ($sub_array as $key = $value){
$policyWriter = $quoteKey|$key|$value;
// ...
  }
}


mh.




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: Parsing file's

2002-05-31 Thread Scott

That's what I mean by starring at this too much :)  I tried writting to a 
seperate file, but is there a way to take an array and split it every so 
many records within another loop?  

Let's say the first row contains the first 18 columns which I already 
parsed, I then want to grab the next 5 15 columns, but need to seperate 
them in groups of 15.  I tried this:

foreach ($output as $key = $value){
  $policyWriter = $quoteKey|$key|$value;
  fwrite ($policyFile,$policyWriter\r\n);
}

Which will take and print the rest of the row, but I needo split the 
columns into groups of 15.

-Scott





On Fri, 31 May 2002, Michael Davey wrote:

 You should normalise your data - have a field in the second csv that links
 to the first csv and then you can have as many rows as you want associated
 with the record in the first file.
 
 Mikey
 
 Scott [EMAIL PROTECTED] wrote in message
 [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
  I have a csv file that I am parsing, formatting and then writting to a new
  file.  I am currently using an array, but I have some lines that might
  contain more data than others.  I know for sure that columns 0-33 will
  always be there, but the customer has the option to add another set of
  columns to the row if needed.  I do know that the addition's will always
  be 18 columns and I do know that they can add up to 15 set's of 18.  So,
  the row length could be 0-33 or 0-51 if they add one additional set or 303
  columns if they go up to 15.
 
  The tricky part is I have to format each column for the new file that is
  created, I do this using sprintf.  I have so far tried to use array_slice
   for the first 18 columns, then I do another array_slice starting at 18
  and using the column count to get the last column in the row.  Here is the
  code:
 
  array_slice($fields, 18,$lineCount);
  foreach ($fields as $key = $value){
  print $key|$value\r\n;
  }
 
  The format of the new file will be this:
  01-Customer information
  02-Other information
  03a Required Info (that can repeat up to 15 times per line)
  03b 
  04b 
  04-Close Customer Record
 
  Repeat cycle for each row.  The inner loop happens between the 02 and 04
  records.  Remember, I need to format each individual column, they are
  different format options.
 
  If you have some thoughts, I would be all ears as I have been starring at
  this too long and too hard.
 
  Thanks,
 
  -Scott
 
 
 
 
 
 

-- 

[EMAIL PROTECTED]

Now Playing: Moby - We Are All Made Of Stars
generated by ProWeb 1.0 Beta
Uptime 168 days
c2002 Exton Communications



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: Parsing file's

2002-05-31 Thread Mark Heintz PHP Mailing Lists

You may have been heading in the right direction originally with
array_slice...  This is off the top of my head, I don't guaruntee it will
work...

$start = 34;
$interval = 15;
$max = 303;
// hop across orig. array 15 columns at a time
for($offset = $start;
$offset  $max  isset($array[$offset]);
$offset += $interval){
  // slice off $interval many columns starting at $offset
  $sub_array = array_slice($array, $i, $interval);
  // handle your $interval many key-value pairs
  foreach ($sub_array as $key = $value){
$policyWriter = $quoteKey|$key|$value;
// ...
  }
}


mh.


On Fri, 31 May 2002, Scott wrote:

 That's what I mean by starring at this too much :)  I tried writting to a
 seperate file, but is there a way to take an array and split it every so
 many records within another loop?

 Let's say the first row contains the first 18 columns which I already
 parsed, I then want to grab the next 5 15 columns, but need to seperate
 them in groups of 15.  I tried this:

 foreach ($output as $key = $value){
   $policyWriter = $quoteKey|$key|$value;
   fwrite ($policyFile,$policyWriter\r\n);
 }

 Which will take and print the rest of the row, but I needo split the
 columns into groups of 15.

 -Scott





 On Fri, 31 May 2002, Michael Davey wrote:

  You should normalise your data - have a field in the second csv that links
  to the first csv and then you can have as many rows as you want associated
  with the record in the first file.
 
  Mikey
 
  Scott [EMAIL PROTECTED] wrote in message
  [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
   I have a csv file that I am parsing, formatting and then writting to a new
   file.  I am currently using an array, but I have some lines that might
   contain more data than others.  I know for sure that columns 0-33 will
   always be there, but the customer has the option to add another set of
   columns to the row if needed.  I do know that the addition's will always
   be 18 columns and I do know that they can add up to 15 set's of 18.  So,
   the row length could be 0-33 or 0-51 if they add one additional set or 303
   columns if they go up to 15.
  
   The tricky part is I have to format each column for the new file that is
   created, I do this using sprintf.  I have so far tried to use array_slice
for the first 18 columns, then I do another array_slice starting at 18
   and using the column count to get the last column in the row.  Here is the
   code:
  
   array_slice($fields, 18,$lineCount);
   foreach ($fields as $key = $value){
   print $key|$value\r\n;
   }
  
   The format of the new file will be this:
   01-Customer information
   02-Other information
   03a Required Info (that can repeat up to 15 times per line)
   03b 
   04b 
   04-Close Customer Record
  
   Repeat cycle for each row.  The inner loop happens between the 02 and 04
   records.  Remember, I need to format each individual column, they are
   different format options.
  
   If you have some thoughts, I would be all ears as I have been starring at
   this too long and too hard.
  
   Thanks,
  
   -Scott




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: Parsing file's

2002-05-31 Thread Scott

Mark-

Trying it now, I think I understand what you doing with the code below.
I'll let you know.

Thank you!

-Scott

-Original Message-
From: Mark Heintz PHP Mailing Lists [mailto:[EMAIL PROTECTED]] 
Sent: Friday, May 31, 2002 4:43 PM
To: Scott
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Re: Parsing file's

You may have been heading in the right direction originally with
array_slice...  This is off the top of my head, I don't guaruntee it
will
work...

$start = 34;
$interval = 15;
$max = 303;
// hop across orig. array 15 columns at a time
for($offset = $start;
$offset  $max  isset($array[$offset]);
$offset += $interval){
  // slice off $interval many columns starting at $offset
  $sub_array = array_slice($array, $i, $interval);
  // handle your $interval many key-value pairs
  foreach ($sub_array as $key = $value){
$policyWriter = $quoteKey|$key|$value;
// ...
  }
}


mh.


On Fri, 31 May 2002, Scott wrote:

 That's what I mean by starring at this too much :)  I tried writting
to a
 seperate file, but is there a way to take an array and split it every
so
 many records within another loop?

 Let's say the first row contains the first 18 columns which I already
 parsed, I then want to grab the next 5 15 columns, but need to
seperate
 them in groups of 15.  I tried this:

 foreach ($output as $key = $value){
   $policyWriter = $quoteKey|$key|$value;
   fwrite ($policyFile,$policyWriter\r\n);
 }

 Which will take and print the rest of the row, but I needo split the
 columns into groups of 15.

 -Scott





 On Fri, 31 May 2002, Michael Davey wrote:

  You should normalise your data - have a field in the second csv that
links
  to the first csv and then you can have as many rows as you want
associated
  with the record in the first file.
 
  Mikey
 
  Scott [EMAIL PROTECTED] wrote in message
  [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
   I have a csv file that I am parsing, formatting and then writting
to a new
   file.  I am currently using an array, but I have some lines that
might
   contain more data than others.  I know for sure that columns 0-33
will
   always be there, but the customer has the option to add another
set of
   columns to the row if needed.  I do know that the addition's will
always
   be 18 columns and I do know that they can add up to 15 set's of
18.  So,
   the row length could be 0-33 or 0-51 if they add one additional
set or 303
   columns if they go up to 15.
  
   The tricky part is I have to format each column for the new file
that is
   created, I do this using sprintf.  I have so far tried to use
array_slice
for the first 18 columns, then I do another array_slice starting
at 18
   and using the column count to get the last column in the row.
Here is the
   code:
  
   array_slice($fields, 18,$lineCount);
   foreach ($fields as $key = $value){
   print $key|$value\r\n;
   }
  
   The format of the new file will be this:
   01-Customer information
   02-Other information
   03a Required Info (that can repeat up to 15 times per line)
   03b 
   04b 
   04-Close Customer Record
  
   Repeat cycle for each row.  The inner loop happens between the 02
and 04
   records.  Remember, I need to format each individual column, they
are
   different format options.
  
   If you have some thoughts, I would be all ears as I have been
starring at
   this too long and too hard.
  
   Thanks,
  
   -Scott




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php