Forum Moderators: coopster
I have a list of data, which each record I want to print to a new line.
I have got the print option working fine, but I now need to register this list into a variable - $output, for later use in the PHP script.
Here is the script I have:
$dbconn = mysql_connect("localhost", "username", "password");
$result = mysql_select_db("database", $dbconn);
$sql = "SELECT field FROM table ORDER BY field ASC";
$result = mysql_query( $sql );
while ( $data = mysql_fetch_assoc( $result ) )
{
$dom = $data['field'];
echo "$dom</br>";
}
I have tried changing the bottom bit to:
{
$dom = $data['field'];
$output = echo "$dom</br>";
}
and also quite a few other variations..but not working.
anyone know how to do this? Any help VERY much appreciated :)
Kindest Regards,
William
(PS: Register_Globals is ON, if that makes any difference)
it prints the list out fine in the browser, but i need the ENTIRE list setting in an $output variable, as it is used in this script below, and needs to print every record on a new line.
$ftp_file = fopen("/www/path/to/file.sh", "w+");
fwrite($ftp_file, $output);
fclose($ftp_file);
trying what you suggested, i changed $output above to $dom, and it printed fine in the browser, but only put one record (the very last alphabetical one) into the .sh file.
any ideas?
In C you deffinitely can't do the kind of assignment I suggested, but I'm pretty sure you can in PHP and certain that you can in either PHP or Perl.
[php.net...]
thanks for your info. this is what i have now:
$result = mysql_query( $sql );
$outputfile = NULL;
$output = array();
while ($data = mysql_fetch_array($result))
{
$dom = $data['field'];
echo "$dom</br>";
}
$outputfile .= "$dom\n";
i think this is wrong, as it is still only writing the very last record into the file?
while ($data = mysql_fetch_array($result))
{
$dom = $data['Zone'];
echo "$dom</br>";
$outputfile = "$dom\n";
}
still no joy :( it writes to the browser fine, just the one last record tp the text file though.
i have the file bit set now to:
$ftp_file = fopen("/www/path/to/file.sh", "w+");
fwrite($ftp_file, $outputfile);
fclose($ftp_file);
(am i missing something completely obvious?)