I am storing my database output in a .txt file. I am not having any problems, but I just want to store 100 rows of MySQL data in one .txt file and the rest in other text files with 100 rows in each file.
Here is my code which is generating all data in only one text file.
<?php
$File = "yourfile.txt";
$Handle = fopen($File, 'w');
$res = mysql_query("SELECT * from tableA");
while ($row = mysql_fetch_array($res)) {
$oumu .= ''.$row4['title'].'';
}
$Data = $oumu;
fwrite($Handle, $Data);
print "Data Added";
fclose($Handle);
?>
It puts all data in one text file but I want to store only 100 rows in one text file and I want to automatically create the next file so that it can store 100 rows in each text file.
Try something like this:
<?php
$res = mysql_query("SELECT * from tableA");
$rows = 0;
$oumu = array();
while ($row = mysql_fetch_array($res)) {
$oumu[floor($rows)] .= ''.$row['title']."
";
$rows += 0.01;
}
foreach ($oumu as $k => $v) {
$File = "yourfile" . ($k + 1) . ".txt";
$Handle = fopen($File, 'w');
fwrite($Handle, $v);
fclose($Handle);
}
print "Data Added";
?>
$i = 0;
while ($row = sql_fetch_array($res)) {
if($i == 100)
break;
$oumu .= ''.$row4['title'].'';
$i++;
}
Also what is the "sql"? Did you mean "mysql_..."?