doutun1875 2014-01-09 22:02
浏览 15
已采纳

php平面文件的麻烦

So im trying to write to a flatfile. A word from a database is written every time it meets a certain criteria. The problem is after the script runs, only the last word that met the criteria shows up in the file. Obviously the words are being written, then over written by the next word. How can i fix this? I want each word to be written to its own line. Heres my code.

<?php

include 'special.class.php';
require 'db_config.php';


$result = mysql_query("SELECT * FROM words limit 0, 30") or die ("Could not make query");

while($row = mysql_fetch_array($result))
{
$word = $row['result'];



$special_word = new word_stuffs( $word);

if ($special_word>is_special()) {


     $File = "words.txt"; 
     $Handle = fopen($File, 'w');
     $Data = $word; 
     fwrite($Handle, $Data);
     fclose($Handle); 

} else {
    echo "Not special!!";
}

}

?>
  • 写回答

1条回答 默认 最新

  • dongyu9263 2014-01-09 22:05
    关注
     $Handle = fopen($File, 'a');
    

    instead of

     $Handle = fopen($File, 'w');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比