looping problem?
| From: | Jas | Date: | Tue, 30 Dec 2003 16:10:14 +0000 |
| Subject: | looping problem? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-173490@lists.php.net to get a copy of this message | ||
Problem with looping over a CSV file (3 results for each line)? Here is the CSV file contents...
MTPC-01,00:02:B3:A2:9D:ED,155.97.15.11
MTPC-02,00:02:B3:A2:B6:F4,155.97.15.12
MTPC-03,00:02:B3:A2:A1:A7,155.97.15.13
MTPC-04,00:02:B3:A2:07:F2,155.97.15.14
MTPC-05,00:02:B3:A2:B8:4D,155.97.15.15
Here is the script...
<?php
$row = 1;
$file = "fa.csv";
$id = fopen("$file","r");
while($data = fgetcsv($id,100,",")) {
$num = count($data);
$row++;
for($c = 0; $c < $num; $c++) {
echo "host $data[0] {<br />\nhardware ethernet $data[1];<br />\nfixed-address $data[2];<br />\n}<br />\n"; }
}
fclose($id);
?>
And this is the output...
(notice 3 results for the first line in the CSV file)
host MTPC-01 {
hardware ethernet 00:02:B3:A2:9D:ED;
fixed-address 155.97.15.11;
}
host MTPC-01 {
hardware ethernet 00:02:B3:A2:9D:ED;
fixed-address 155.97.15.11;
}
host MTPC-01 {
hardware ethernet 00:02:B3:A2:9D:ED;
fixed-address 155.97.15.11;
}
Any help is appreciated...
Jas