looping and writing to a file
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

looping and writing to a file

From: Aaron Reimann <aaron.reimann@gmail.com>
Date: Mon Jul 18 2005 - 04:35:11 CEST

I have a function here that will (with some other functions not shown
here) display some results from a database. Here is the code:

function display_song_list($fd, $e) {
        global $sys_install_base;
        global $sys_relative_uploaddir;

        echo ("<songs>\n");

        foreach ($e as $error) {
                echo ("$error\n");
        }

        $c = pg_numrows($fd['result']);
        for ($i = 0; $i < $c; $i++) {
                $r = pg_fetch_assoc($fd['result'], $i);

                echo ("<song title=\"{$r['song_title']}\" artist=\"{$r['artist']}\"
path=\"{$sys_install_base}{$sys_relative_uploaddir}{$r['audio_file']}\"/>\n");

        }

        echo ("</songs>");

}

I need some help writing the info to a text file. I know the 'fopen'
and 'fwrite' stuff. But I don't how to write <songs>, and then write
out all of the rows from the database, and then write </songs>.

Thank you for your help.

Aaron
Received on Mon Oct 17 21:09:39 2005