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>';

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.