aebstract Posted February 15, 2010 Share Posted February 15, 2010 <?php $myFile = "array.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $query = mssql_query("SELECT * FROM ordnn_users"); if(mssql_num_rows($query) > 0){ while($r=mssql_fetch_array($query)){ echo "<pre>"; print_r($r); echo "</pre>"; fwrite($fh, $r); } } else { echo mssql_get_last_message(); } fclose($fh); ?> Okay, I have this query that grabs info and just display the information from that table. Which works fine, when I try and write that information in to a txt file, the file ends up with the word Array written over and over for as many times as there are results. How can I get it to write the actually information inside the array? If I could have it write as it shows for print_r() that would be great, needing to take this array manually over to another server. If I write $r[1] it seems to display actual data in the textfile, but I'm having trouble formatting it. Link to comment https://forums.phpfreaks.com/topic/192150-help-with-fwrite/ Share on other sites More sharing options...
aebstract Posted February 15, 2010 Author Share Posted February 15, 2010 I think I got it, for writing to a textfile if I literally press enter and go down a space in the code it'll put a space for me. Also I have to use exact [1] [2] paths for the array to grab the data. At least it lets me do it! Link to comment https://forums.phpfreaks.com/topic/192150-help-with-fwrite/#findComment-1012657 Share on other sites More sharing options...
Andy-H Posted February 15, 2010 Share Posted February 15, 2010 <?php $myFile = "array.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $query = mssql_query("SELECT * FROM ordnn_users"); if(mssql_num_rows($query) > 0){ while($r=mssql_fetch_array($query)){ echo "<pre>"; print_r($r); echo "</pre>"; $str = '<pre>' . print_r($r, true) . '</pre>' . PHP_EOL; fwrite($fh, $str); } } else { echo mssql_get_last_message(); } fclose($fh); ?> With the second print_r param set to true, the output is captured as a string value. Link to comment https://forums.phpfreaks.com/topic/192150-help-with-fwrite/#findComment-1012659 Share on other sites More sharing options...
aebstract Posted February 15, 2010 Author Share Posted February 15, 2010 <?php $myFile = "array.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $query = mssql_query("SELECT * FROM ordnn_users"); if(mssql_num_rows($query) > 0){ while($r=mssql_fetch_array($query)){ echo "<pre>"; print_r($r); echo "</pre>"; $str = '<pre>' . print_r($r, true) . '</pre>' . PHP_EOL; fwrite($fh, $str); } } else { echo mssql_get_last_message(); } fclose($fh); ?> With the second print_r param set to true, the output is captured as a string value. With this text file, if I put it on another server, can I easily loop through it like my original query's while loop so that I can use the information how I need to? Would I loop through each line on the text file or something? Link to comment https://forums.phpfreaks.com/topic/192150-help-with-fwrite/#findComment-1012691 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.