|
Posted by Andrew @ Rockface on 07/01/05 10:37
In news:pI5xe.81321$gc6.36806@okepread04,
Kees Boer <keesboer@integrity-computing.net> wrote:
> Hi, Andrew!
>
> No, I don't use COBOL any more, but I kind of liked the language in
> the sense that if you don't mind typing, I liked how it was so easy
> to read and understand what was going on. What I didn't like was all
> the moving and picture statements. Actually, I think my favorite
> language for database processing has got to be the old dBase/FoxPro
> language. I worked with that for 8 or 9 years and got to be very good
> at it and fast.
>
> I could put a system together in 4 hours with menus and everything. I
> still wonder, why it all has got to become so complicated. In dBase
> if you want to open a database file, you would just say: "use
> inventor." There was no connecting and all of the other stuff you had
> to do. With Foxpro, you could use SQL statements, but you were able
> to make them in their query manager and then just copy and paste them
> right into the code. For some reason, it all has gotten a lot more
> complicated. I don't understand, because it was supposed to be gotten
> simpler.
I learnt coding using cobol and pascal, and the dataease dbms which was
pretty lovely to use.
> Oh, well, I'm rambling. It's 2:45 AM here.
>
> Thank you for the code! I appreciate it. How do you do skip to the
> next record and position yourself at the top?
To break out of the current itteration and start the next itteration use
'continue'.
To exit the loop completely use 'break'.
> I need to do that,
> because I need to write a Ctrl-Break type program. If I have gotten
> 32 records processed, I need to start a new webpage.
I'm not exactly sure what you need but:-
// Read all lines in the file into an array, one line per array element.
$lines = file('filename');
// Cycle through the array starting at the first element (first line in the
file)
// $line_num is the current array element/line number.
// $line is the contents of the array element
foreach ($lines as $line_num => $line) {
// Process until 32nd line
if (($line_num + 1) == 32) {
// Exit loop
break;
}
process $line...
}
OR:
$lines = file('filename');
for ($c = 1; $c < count($lines); $c++) {
if ($c == 32) {
break;
}
process $lines[$c]...
}
If you want to start a new table at record 32 try:
$lines = file('filename');
echo "<table>\n";
for ($c = 0; $c < count($lines); $c++) {
echo "<tr><td>".$lines[$c]."</td></tr>\n";
if ($c == 32) {
echo "</table>\n<table>"
}
}
Or every 32nd record:
$lines = file('filename');
echo "<table>\n";
for ($c = 0; $c < count($lines); $c++) {
echo "<tr><td>".$lines[$c]."</td></tr>\n";
// Use modulus to test if current line cleanly divides into 32
// I may have cocked this bit up as I haven't tested any
// of this code, but I'm sure you get the idea.
if (32 % $c) {
echo "</table>\n<table>"
}
}
--
Andrew @ Rockface
np: Blind Willie Johnson - Mother's Children Have A Hard Time
www.rockface-records.co.uk
[Back to original message]
|