while($row= mysql_fetch_object($result)){
$row->products_price=$row->products_price-($row->products_price*0.05);
echo $row->products_id ." ". $row->products_price."<br/>";
}
如何将$row->products_id ." ". $row->products_price
放入一行一行的txt文件中?
答案 0 :(得分:3)
$content = "";
while ( $row = mysql_fetch_object($result) ){
$row->products_price = $row->products_price-($row->products_price * 0.05);
$content .= $row->products_id . " " . $row->products_price . "\r\n";
}
file_put_contents("filename.txt", $content, LOCK_EX);
编辑:( Hikaru-Shindo的版本)
while ( $row = mysql_fetch_object($result) ){
$row->products_price = $row->products_price-($row->products_price * 0.05);
file_put_contents("filename.txt", $row->products_id . " " . $row->products_price . "\r\n", FILE_APPEND | LOCK_EX);
}
答案 1 :(得分:0)
$fh = fopen("myfile.txt", "w+");
while($row= mysql_fetch_object($result))
{
$row->products_price=$row->products_price-($row->products_price*0.05);
fwrite($fh, $row->products_id ." ". $row->products_price."\r\n");
}
fclose($fh);