summaryrefslogtreecommitdiffstats
path: root/system/database/DB_utility.php
diff options
context:
space:
mode:
authorMichelle Jones <michelledeannejones@gmail.com>2013-02-27 22:59:48 +0100
committerMichelle Jones <michelledeannejones@gmail.com>2013-02-27 22:59:48 +0100
commitb76e29242fd399c47ec633152092f9ce7ac917fc (patch)
tree8dc5ff19d936e5d001ffbadffb9929efb12bdd7c /system/database/DB_utility.php
parentaf493e6699ee548331a4557dba9162ec8b789fbf (diff)
Remove trailing delimiters from csv_from_result
When using the csv_from_result function, the returned string includes an extra delimiter at the end of every line, usually a comma unless another delimiter is specified. A simple addition of a couple of lines to remove the extra delimiter from the column names and the data rows is included. (Lines 241 and 251)
Diffstat (limited to 'system/database/DB_utility.php')
-rw-r--r--system/database/DB_utility.php4
1 files changed, 3 insertions, 1 deletions
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index 9822fdaa3..9803307ed 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -238,7 +238,8 @@ abstract class CI_DB_utility {
$out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim;
}
- $out = rtrim($out).$newline;
+ $out = substr(rtrim($out),0,-strlen($delim)); // Remove the trailing delimiter character(s) at the end of the column names
+ $out = $out.$newline;
// Next blast through the result array and build out the rows
while ($row = $query->unbuffered_row('array'))
@@ -247,6 +248,7 @@ abstract class CI_DB_utility {
{
$out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim;
}
+ $out = substr(rtrim($out),0,-strlen($delim)); // Remove the trailing delimiter character(s) at the end of the row lines
$out = rtrim($out).$newline;
}