Jump to content

how to put the content retrieved from database to a text file (data.txt)


tayhaithian

Recommended Posts

assume the below code working . How do i put the retrieved output into the text file (data.txt) .

 

echo '<table border=0>';
echo '<tr>';
echo '<td>';
$test = mysql_num_rows($result);
if($test == 0)
{
echo 'empty';
}
$i=1;
echo '<dl>';
while($row=mysql_fetch_array($result))
{
$test = $row["category_name"];
//echo $id;
echo '<dt>',$i++," ",$row["category_name"],'</dt>';



$subc = mysql_query("select topic_subject, category_name, circ_title from topic_tbl, category_tbl, circulation_tbl where topic_tbl.topic_id = category_tbl.topic_id and category_tbl.category_id = circulation_tbl.category_id and topic_tbl.topic_id = $data and category_tbl.category_name = '$test' ");
	while($wow=mysql_fetch_array($subc))
	{
	echo '<dd>',$wow["circ_title"],'</dd>';
	}


}
echo '</dl>';
echo '</td>';
echo '</tr>';
echo '</table>';

while($row=mysql_fetch_array($result))
{
   $test = $row['category_name'];
   $string .= "</pre>
<dt>$i++ - $row['category_name']</dt>\n";<br>}<br><br>$fd = fopen("log.txt", "w+");<br>fwrite($fd, $string);<br>fclose

 

EDIT - Fixed string and added newline

Yeah, you can't put an array variable within double quotes like that. It needs to either be appended to the string using something like this

$string .= "<dt>$i++ - " . $row['category_name'] . "</dt>\n";

 

Or you can enclose in brackets like this:

$string .= "<dt>$i++ - {$row['category_name']}</dt>\n";

 

I prefer the latter.

cases is like this , i wan smtg like category and its subcategory where i used 2 while loop in the code

 

1 blablablablabla

     


  •        
  •   asdasdasd
           
  •   asasdasdasd
           
  •   asdasdasd
     

 

2 wahhoooooo

     


  •        
  •   asdasdasd
           
  •   asasdasdasd
           
  •   asdasdasd
     

 

while($row=mysql_fetch_array($result))
   {
   $test = $row["category_name"];
   //echo $id;
   echo '<dt>',$i++," ",$row["category_name"],'</dt>';
   
   
   
   $subc = mysql_query("select topic_subject, category_name, circ_title from topic_tbl, category_tbl, circulation_tbl where topic_tbl.topic_id = category_tbl.topic_id and category_tbl.category_id = circulation_tbl.category_id and topic_tbl.topic_id = $data and category_tbl.category_name = '$test' ");
      while($wow=mysql_fetch_array($subc))
      {
      echo '<dd>',$wow["circ_title"],'</dd>';
      }
   
   
   }

 

 

 

 

and then i wanna overwrite the list whenever there is a changes .

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.