Reputation: 3648
How do I get all data from one row from mysql table exported into text files, but formatted this way:
...using php script or just mysql console?
Upvotes: 0
Views: 374
Reputation: 562931
I might do it this way, using the command-line client:
$ mysql --user=XXX --password=XXX --batch --skip-column-names \
-e "SELECT userid, displayname FROM Users" stackoverflowdb | \
split -l 50 -a 5 - "result."
Upvotes: 2
Reputation: 53921
I hate doing peoples homework/work, but this one is just too easy.
<?
$row = mysql_fetch_array($rc);
$nodupes = array();
foreach ($row as $field)
{
$nodupes[$field] = $field;
}
$i = 1;
$filenum = 0;
$line = 50 ; // create new file ever 50 lines
$text = "";
foreach($nodupes as $field)
{
$i++;
$text .= "$field\n";
// to split into bite size peices
if ($i % $line == 0)
{
$filenum++;
$filename = "myfile_$filenum.txt";
file_put_contents($filename,$text);
$text = "";
}
}
$filenum++;
$filename = "myfile_$filenum.txt";
file_put_contents($filename,$text);
?>
So eat today, and learn to fish another day!
Upvotes: 0