|
Thread: cvs
-
May 19th, 2007, 06:30 PM
#1
Thread Starter
Frenzied Member
cvs
Hi how can I use CVS? I meant how can I make a cvs file?
-
May 19th, 2007, 08:10 PM
#2
Re: cvs
You need to download it if you don't already have it.
http://ftp.gnu.org/non-gnu/cvs/
Moved.
-
May 20th, 2007, 04:20 AM
#3
Re: cvs
- does he mean CSV?
-
May 20th, 2007, 04:24 AM
#4
-
May 20th, 2007, 04:24 AM
#5
Re: cvs
I am glad I gave you that negative rep.
-
May 20th, 2007, 09:07 AM
#6
Re: cvs
 Originally Posted by visualAd
 - does he mean CSV? 
LOL... CVS is pharmacy chain in my town.
 Originally Posted by vbbit
Hi how can I use CVS? I meant how can I make a cvs file?
Where is the data come from and what language do you use to program?
Last edited by RhinoBull; May 20th, 2007 at 09:10 AM.
-
May 20th, 2007, 11:38 AM
#7
Thread Starter
Frenzied Member
Re: cvs
The data will be coming from mysql, and I want to use PHP to program. Is it CVS or CSV? lol.. P told me to download something I have no idea.
-
May 20th, 2007, 11:53 AM
#8
Re: cvs
 Originally Posted by vbbit
The data will be coming from mysql, and I want to use PHP to program. Is it CVS or CSV? lol.. P told me to download something I have no idea.
In that case you better off posting this in PHP forum directly or ask mods to move it.
And it's CSV - comma separated values (if that's what you need).
-
May 20th, 2007, 12:25 PM
#9
Re: cvs
 Originally Posted by RhinoBull
In that case you better off posting this in PHP forum directly or ask mods to move it.
And it's CSV - comma separated values (if that's what you need).
Don't you mean ask the mods to move it back?
-
May 20th, 2007, 12:48 PM
#10
Re: cvs
CSV = Comma Separated Values.
They are very easy to create, you just need to ensure you follow the following rules:
- Each row is terminated with a carriage return / line feed "\r\n" in terms of PHP.
- Fields are separated by commas.
- Fields that contain strings with spaces, commas or newlines are enclosed in double quotes.
- Double quotes inside strings are escaped with two successive double quotes " "" ".
- The first row may be the column names.
You could have a simple class that creates it for you:
PHP Code:
class CSVCreator
{
private $rows = array();
/* an array of data to add */
public function addRow($data)
{
if (! is_array($data)) {
throw new Exception('Bad data format');
}
$this->rows[] = $data;
}
/* $cols can contain an array of column names */
public function create($cols = null)
{
$ret = '';
$rows = $this->rows; // get a copy of the data
if (is_array($cols)) {
// prepend to the beginning of the arrray
array_unshift($rows, $cols);
}
foreach ($rows as $row) {
$strRow = '';
foreach($row as $col) {
if (! is_numeric($col)) {
// enclose all strings in quotes and escape quotes
$col = '"' . str_replace('"', '""', $col) . '"';
}
$strRow .= $col . ',';
}
$strRow = substr($strRow, 0, -1); // strip off the last comma if needed
$ret .= $strRow . "\r\n";
}
// strip off last line break \r\n
$ret = substr($ret, 0, -2);
return $ret;
}
}
You use it by simply supplying it with the results from a function like mysql_fetch_row().
PHP Code:
$csv = new CSVCreator;
while (($row = mysql_fetch_row())) {
$csv->addRow($row);
}
echo($csv->create());
-
May 20th, 2007, 12:55 PM
#11
Re: cvs
 Originally Posted by visualAd
Don't you mean ask the mods to move it back? 
Ah... just noticed that.
-
May 21st, 2007, 02:06 PM
#12
Thread Starter
Frenzied Member
Re: cvs
Oh so after I got that csv file, what is its extension I should save to? and how can I insert it in Ms. Access? or sql server?
-
May 21st, 2007, 02:56 PM
#13
Re: cvs
Save it with whatever extension you like. Although as it is a CSV file, using a .csv extension would be the most logical thing to do.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|