how to write displayed db data into a file
Posted: Tue Jan 03, 2012 4:49 pm
hello sirs,
Kindly I need some help. I can connect to and display my data properly from the DB. I want to write the displayed data to a text file. I cant figure out where to put things, considering the while statement in my code.
I have tried this after scouring through the net:
and I get an error sayiing "an expected $end"......somewhere
Kindly I need some help. I can connect to and display my data properly from the DB. I want to write the displayed data to a text file. I cant figure out where to put things, considering the while statement in my code.
Code: Select all
$query="SELECT * FROM mytable";
$result=mysql_query($query);
$num=mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>
<td>".$row['field1']."</td>
<td>".$row['field2']."</td>
<td>".$row['field3']."</td>
</tr>";
}
?>
Code: Select all
<?php
$fp = fopen($filename, "w");
$query="SELECT * FROM mytable";
$result=mysql_query($query);
$num=mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>
<td>".$row['field1']."</td>
<td>".$row['field2']."</td>
<td>".$row['field3']."</td>
</tr>";
flose ($fp);