There is a white-space in "[Field 16 "]
. Fix it in the CSV. This will solve your problem.
I can't get the specific field in csv file
-
19-10-2022 - |
문제
just want to ask... why i can't get the Field 16 data? here's my code to get the data in csv file using codeigniter
this is in my controller:
public function index()
{
$this->load->library('csvreader');
$filePath = 'C:\xampp\htdocs\Datacast\pdw_table.csv';
$data['csvData'] = $this->csvreader->parse_file($filePath);
die();
echo '<pre>';
print_r($data);
die();
echo '</pre>';
$this->load->view('myform', $data);
}
this is my view:
<table cellpadding="0" cellspacing="0">
<thead>
<th>
<td>Field 1</td>
<td>Field 2</td>
<td>Field 3</td>
<td>Field 16</td>
</th>
</thead>
<tbody>
<?php foreach($csvData as $field)
{?>
<tr>
<td><?php echo $field['Field 1']; ?></td>
<td><?php echo $field['Field 2']; ?></td>
<td><?php echo $field['Field 3']; ?></td>
<td><?php echo $field['Field 16']; ?></td>
</tr>
<?php }?>
</tbody>
</table>
everytime i print_r the $data in controller here's the output
Array
(
[csvData] => Array
(
[0] => Array
(
[Field 1] => Myanmar
[Field 2] => MPT_ONE
[Field 3] => B7VIET-STP-0
[] =>
[Field 4] => 0
[Field 5] => A
[Field 6] => 1
[Field 7] => HW_SX/SPC
[Field 8] => STP
[Field 9] => 4.28.1
[Field 10] => 8417
[Field 11] => VINAPHONE (Vietnam)/STP
[Field 12] => STP
[Field 13] => 4.104.3
[Field 14] => 9027
[Field 15] => HNI/VTI-YGN/MPT 30N001 (Vietnam-1)
[Field 16
] => 1.1.1
)
[1] => Array
(
[Field 1] => Myanmar
[Field 2] => MPT_ONE
[Field 3] => B7VIET-STP-1
[] =>
[Field 4] => 0
[Field 5] => A
[Field 6] => 1
[Field 7] => HW_SX/SPC
[Field 8] => STP
[Field 9] => 4.28.1
[Field 10] => 8417
[Field 11] => VINAPHONE (Vietnam)/STP
[Field 12] => STP
[Field 13] => 4.104.4
[Field 14] => 9028
[Field 15] => HCN/VTI-YGN/MPT 30N002 (Vietnam-2)
[Field 16
] => 1.1.1
)
[2] => Array
(
[Field 1] => Myanmar
[Field 2] => MPT_ONE
[Field 3] => LKBELGA1
[] =>
[Field 4] => 0
[Field 5] => A
[Field 6] => 1
[Field 7] => DMS_NPT/SPC
[Field 8] => STP
[Field 9] => 4.28.3
[Field 10] => 8419
[Field 11] => BELGACOM-Belgium/STP
[Field 12] => STP
[Field 13] => 2.13.1
[Field 14] => 4201
[Field 15] => BRUSSELS-YANGON30N001
[Field 16
] => 1.1.2
)
[3] => Array
(
[Field 1] => Myanmar
[Field 2] => MPT_ONE
[Field 3] => LKSOFT1
[] =>
[Field 4] => 0
[Field 5] => A
[Field 6] => 1
[Field 7] => DMS_NPT/SPC
[Field 8] => STP
[Field 9] => 4.28.3
[Field 10] => 8419
[Field 11] => SOFTBANK-Japan/STP
[Field 12] => STP
[Field 13] => 4.85.1
[Field 14] => 8873
[Field 15] => CHB/SBT-YGN30N002
[Field 16
] => 1.1.2
)
here is the output in var_dump()
array(1) {
["csvData"]=>
array(37) {
[0]=>
array(18) {
["Field 1"]=>
string(7) "Myanmar"
["Field 2"]=>
string(7) "MPT_ONE"
["Field 3"]=>
string(12) "B7VIET-STP-0"
[""]=>
string(0) ""
["Field 4"]=>
string(1) "0"
["Field 5"]=>
string(1) "A"
["Field 6"]=>
string(1) "1"
["Field 7"]=>
string(9) "HW_SX/SPC"
["Field 8"]=>
string(3) "STP"
["Field 9"]=>
string(6) "4.28.1"
["Field 10"]=>
string(4) "8417"
["Field 11"]=>
string(23) "VINAPHONE (Vietnam)/STP"
["Field 12"]=>
string(3) "STP"
["Field 13"]=>
string(7) "4.104.3"
["Field 14"]=>
string(4) "9027"
["Field 15"]=>
string(35) "HNI/VTI-YGN/MPT 30N001 (Vietnam-1)"
["Field 16"]=>
string(5) "1.1.1"
["
"]=>
string(2) "
"
}
[1]=>
array(18) {
["Field 1"]=>
string(7) "Myanmar"
["Field 2"]=>
string(7) "MPT_ONE"
["Field 3"]=>
string(12) "B7VIET-STP-1"
[""]=>
string(0) ""
["Field 4"]=>
string(1) "0"
["Field 5"]=>
string(1) "A"
["Field 6"]=>
string(1) "1"
["Field 7"]=>
string(9) "HW_SX/SPC"
["Field 8"]=>
string(3) "STP"
["Field 9"]=>
string(6) "4.28.1"
["Field 10"]=>
string(4) "8417"
["Field 11"]=>
string(23) "VINAPHONE (Vietnam)/STP"
["Field 12"]=>
string(3) "STP"
["Field 13"]=>
string(7) "4.104.4"
["Field 14"]=>
string(4) "9028"
["Field 15"]=>
string(34) "HCN/VTI-YGN/MPT 30N002 (Vietnam-2)"
["Field 16"]=>
string(5) "1.1.1"
["
"]=>
string(2) "
"
}
i don't know why the data of Field 16 is entered..
해결책
제휴하지 않습니다 StackOverflow