Jump to content

help with fwrite


aebstract

Recommended Posts

<?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

<?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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.