Jinovich
12-25-2008, 05:11 PM
I have no trouble writing to a file my problem is I can not think of a way to print the array into a variable so I can write it to the file. I can only seem to write one row. Because obviously the variable gets rewrtten in the while loop.
Can someone help me with this I have been struggling with it for sometime.
<?php
include("../config.php");
$get = mysql_query("SELECT * FROM users ORDER BY username ASC");
while($slot = mysql_fetch_array($get))
{
$content = "".$slot[username]." - ".$slot[slots]."<br>";
}
$filename = 'test.html';
// Let's make sure the file exists and is writable first.
//if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $content) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($content) to file ($filename)";
fclose($handle);
//} else {
//echo "The file $filename is not writable";
//}
?>
Oh and merry christmas :)
Can someone help me with this I have been struggling with it for sometime.
<?php
include("../config.php");
$get = mysql_query("SELECT * FROM users ORDER BY username ASC");
while($slot = mysql_fetch_array($get))
{
$content = "".$slot[username]." - ".$slot[slots]."<br>";
}
$filename = 'test.html';
// Let's make sure the file exists and is writable first.
//if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $content) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($content) to file ($filename)";
fclose($handle);
//} else {
//echo "The file $filename is not writable";
//}
?>
Oh and merry christmas :)