Professional CodeIgniter, Thomas Myer
Chapter 7: Improving the Dashboard
201
echo "
<
th
>
".$hdr."
<
/th
>
\n";
}
}
?
>
<
/tr
>
Next, loop through the entire
$csv
array, and print out any data you may find. Remember to trim for
white space and create hidden form fields as you go. Also note that each hidden form field is an array
whose key corresponds to the line number you ' re processing in the
whose key corresponds to the line number you ' re processing in the
$csv
array. This may sound
confusing, but it will keep all your data neatly packaged when it comes time to process it. You want to
end up with an array of elements, with line numbers for keys and the corresponding data for each line as
the values. That way you can easily unpack what you need on the other side and have it match the
incoming CSV data.
end up with an array of elements, with line numbers for keys and the corresponding data for each line as
the values. That way you can easily unpack what you need on the other side and have it match the
incoming CSV data.
<
?php
foreach ($csv as $key =
>
$line){
echo "
<
tr valign='top'
>
\n";
foreach ($line as $f =
>
$d){
$FIELD = trim(str_replace(`"','',$f));
$FDATA = trim(str_replace(`"','',$d));
if ($FIELD != `'
&
&
!eregi("thumbnail",$FDATA)
&
&
!eregi("image",$FDATA)){
echo "
<
td
>
";
echo $FDATA . "\n";
echo form_hidden("line_$key"."[".$FIELD."]",$FDATA);
echo "
<
/td
>
\n";
}
}
echo "
<
/tr
>
\n";
}
?
>
<
/table
>
Don ' t forget to add the important
csvgo
hidden field. That way the
import()
function will know how
to process the incoming request.
<
?php
echo form_hidden(`csvgo',true);
echo form_close();
Finally, print out an error message if the incoming
$csv
array is empty.
}else{
echo "
<
h1
>
We detected a problem...
<
/h1
>
";
echo "
<
p
>
No records to import! Please try again.
<
/p
>
";
}
?
>
The result of all your efforts should look like Figure 7 - 7 .
c07.indd 201
c07.indd 201
6/10/08 5:36:42 PM
6/10/08 5:36:42 PM