Here is a function I use to write data to a file (It is similar to PHP 5's file_put_contents but works for those who don't have a PHP 5 installation:) function file_put_contents($filename, $data, $file_append = false) { $fp = fopen($filename, (!$file_append ? 'w+' : 'a+')); if(!$fp) { trigger_error('file_put_contents cannot write in file.', E_USER_ERROR); return; }; fputs($fp, $data); fclose($fp); }; in addition to using the above code, be sure that you are writing to a folder in which you have write permissions. Once the function is available to your code you can write your data in a manner like this: file_put_contents('/root/directory/pathtoyourfile/mydata.txt',$filecontent); Mark Cain ----- Original Message ----- From: "mayo" <mayo@xxxxxxxxxxxxxxxxxx> To: <php-general@xxxxxxxxxxxxx> Sent: Wednesday, June 01, 2005 7:01 PM Subject: write to file question, rewritten > I'm trying to write the results of a mysql_fetch_array db query to a > file and am unable to. > > I'm putting the results into a variable $fileContent and then using > fwrite(). > > I would have liked to do something like: > > $filecontent = > > . > > > $result = mysql_query( " > > SELECT orderedItems.*, items.* > FROM orderedItems, items > WHERE > orderedItems.orderID=$orderID[0] AND > orderedItems.itemID=items.itemsID > > "); > > while($row = mysql_fetch_array( $result )) > { > > $theItemID=$row["orderedItems.itemID"]; > $theItemPrice=$row["itemPrice"]; > $theItemQty=$row["itemQty"]; > > $thisItemID= sprintf("% 6d",$theItemID); > $thisItemPrice= sprintf("%7.2f",$theItemPrice); > $thisItemQty= sprintf("% 7d",$theItemQty); > > $thisOrder . > > $thisItemID . > > $thisItemPrice . > > $thisItemQty . > } > > "; // end of $filecontent > > but that doesn't work. > > Mayo > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php