write a file in php
<p>This function fetches the records from the db. Now I want it to write them to a file. Please help me.   </p>

<pre><code>function selectcsv($classname)
    {
        echo $sql = "SELECT * FROM tblstuden WHERE classname = $classname;"; 
        $obj_db = new DB();
        $obj_db-&gt;query($sql);

        while($row = $obj_db-&gt;rsset()){
        $this-&gt;_id($row[id]);
        $this-&gt;_studentname($row[studentname]);
        $this-&gt;_rollnumber($row[rollnumber]);
        $this-&gt;_classname($row[classname]);

        $out = $out . $row[studentname] . " , ". $row[rollnumber] . "\n";
        }

        $obj_db-&gt;db_close();
</code></pre>

<p>The above portion is running</p>

<pre><code>$myFile = "write.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "write::";
fwrite($fh, $stringData);
$stringData = $_POST[read];
fwrite($fh, $stringData);
fclose($fh);
</code></pre>
