User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 402,575 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,302 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting

Generate text document from Php

Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation: johny_d is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
johny_d's Avatar
johny_d johny_d is offline Offline
Junior Poster in Training

Re: Generate text document from Php

  #2  
May 10th, 2007
You can find it in the php manual if you do a little search
Here is that code adjusted to what you need:
[php]
<?php

/// here is your database connection

/// than the query
$result = mysql_query ("select field_1, field_2, field_3 from table") or die (mysql_error());

$filename = $_SERVER['DOCUMENT_ROOT'].'/test.xls'; //// or whatever.txt

if (!$handle = fopen($filename, 'a')) {
print "Cannot open file ($filename)";
exit;
}
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

while ($row = mysql_fetch_row($result)) {
$row_content = implode ("\t",$row)."\r\n";
// Write $row_content to our opened file.
if (!fwrite($handle, $row_content)) {
print "Cannot write to file ($filename)";
exit;
}
}

print "Success, content wrote to file ($filename)";

fclose($handle);

} else {
print "The file $filename is not writable";
}

?>

[/php]

Try to do the basics first (like reading the manual)
Last edited by johny_d : May 10th, 2007 at 8:01 am.
Reply With Quote  
All times are GMT -4. The time now is 10:45 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC