> I am trying to make a tab delimited file of a mysql table so I can open
> it with Excel.
> I select the data - 40 fields, 808 records no prob.
> I view a mysql_num_rows() query to make sure it selects all records; no
prob.
>
> I create a tab delimited format:
> $result = mysql_query("SELECT * FROM $database");
> $rows=mysql_num_rows($result);
> while ($row = mysql_fetch_array($result) )
> {
> $field1="$row[field1]";
> $field2="$row[field2]";  file://etc....
>
> $html.="$field1 $field2 $field3....."

I'm assuming there are TAB characters in there?...

Actually, though, you could save yourself some grief here and just do
explode("\t", $row) to get your line to output.

> }
>
> Then I write it to a file:
> if (! ($myfile=fopen ("tables", "w")))  {echo "file could not be opened";}
> fputs ($myfile, "$html");
> fclose ($myfile);
>
> THE PROBLEM IS...
>
> The file that is written is missing about 400 records!
> If I limit the fields to a few, I get all 808 records written no problem.
> So, I imagine the problem is the file size - the 400 records equate to
> about 131K.
> Is there a problem using the fputs() function for larger files?

There shouldn't be any problem.  A few hundred K is just not that big.

However, you could make this more efficient by opening the file when you do
the query, and spitting out each line as you get it.

I dunno what's going wrong, but you'll have a way better program, and maybe
the gods will smile on you then and let it work. :-)



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to