tayhaithian Posted April 8, 2009 Share Posted April 8, 2009 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>'; Quote Link to comment Share on other sites More sharing options...
Maq Posted April 8, 2009 Share Posted April 8, 2009 Store it in a string and use fopen and fwrite to store it in a text file. Quote Link to comment Share on other sites More sharing options...
tayhaithian Posted April 8, 2009 Author Share Posted April 8, 2009 Maq, i appreciate the reply . Can i hve slightly more guiadance ? (Im using while loop to retrieve.) Quote Link to comment Share on other sites More sharing options...
Maq Posted April 8, 2009 Share Posted April 8, 2009 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 Quote Link to comment Share on other sites More sharing options...
tayhaithian Posted April 8, 2009 Author Share Posted April 8, 2009 it doesnt work for the line $string .= "<dt>$i++ - $row['category_name']</dt>\n"; error : Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 8, 2009 Share Posted April 8, 2009 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. Quote Link to comment Share on other sites More sharing options...
tayhaithian Posted April 8, 2009 Author Share Posted April 8, 2009 hmm . $string .= "<dt>$i++ - {$row['category_name']}</dt>\n"; this seems to be fine . but " \n " doesnt go to new line . howcome ? Quote Link to comment Share on other sites More sharing options...
tayhaithian Posted April 8, 2009 Author Share Posted April 8, 2009 edited* how do i open and save into the file without overwrite it ~ Quote Link to comment Share on other sites More sharing options...
redarrow Posted April 8, 2009 Share Posted April 8, 2009 post your current code then. Quote Link to comment Share on other sites More sharing options...
tayhaithian Posted April 8, 2009 Author Share Posted April 8, 2009 how do i open and save into the file without overwrite it ~ Quote Link to comment Share on other sites More sharing options...
tayhaithian Posted April 8, 2009 Author Share Posted April 8, 2009 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 . Quote Link to comment Share on other sites More sharing options...
Maq Posted April 8, 2009 Share Posted April 8, 2009 In order to not overwrite what you previously put in the file you must open with append, like so: $fd = fopen("log.txt", "a"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.