Forum Moderators: coopster
I need the column headers from the file to be placed in the right colums in the table.
phppgadmin has a function which does essentially what I am trying to do but will only work with CSV or XML. When I upload a CSV it doesn't matter which order the columns are in-- the values are inserted into the correct column in the table.
I've tried rewriting the function from that package to suit my needs but I can't get it to work.
How can I write a loop which will verify the column names instead of just looping through and putting the values in sequentially across the row?
Thanks, I appreciate the help
[us2.php.net...]
while ($line = fgetcsv($fd, $csv_max_line, $csv_delimiter))
That is from the phppgadmin dataimport. It's followed by a foreach loop
I am trying to translate it since I am not using a csv.
If I understand correctly fgetcsv returns an array right? Well so I thought maybe I could just replace everything after the = with my array variable.. but it doesn't seem to work
No, I didn't.
It bombs out here and returns Row 2
// Get first line of field names
$fields = $sheetArray;
$row = 2; //We start on the line AFTER the field names
while ($line = $sheetArray) {
// Build value map
$vars = array();
$nulls = array();
$format = array();
$types = array();
$i = 0;
foreach ($fields as $f) {
// Check that there is a column
if (!isset($line[$i])) {
echo '<br><br>' . $row;
exit;
}