我有以下内容:
$sql5 = "select *,count(*) from rc_language_type_assoc_table group by language_type_id";
$result5 = mysql_query($sql5); //not correct
$count5 = mysql_num_rows($result5); //not correct
$myFile = "/home/rainbowcode/StatsFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $sql5."\n");
$myFile = "/home/rainbowcode/StatsFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $result5."\n");
以上不是我想要的,我希望select的实际结果集在我的StatsFile中打印 我怎么能实现这个呢???
答案 0 :(得分:3)
不是最有效的解决方案,但应该让您了解如何完成工作
$sql5 = "select *,count(*) from rc_language_type_assoc_table group by language_type_id";
$result5 = mysql_query($sql5); //not correct
$count5 = mysql_num_rows($result5); //not correct
$myFile = "/home/rainbowcode/StatsFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $sql5."\n");
while ($row = mysql_fetch_assoc($result5) {
foreach ($row as $key => $val) {
fwrite($fh, "$key=>$val ");
}
fwrite($fh, "\n");
}
fclose($fh);
答案 1 :(得分:0)
您需要获取每一行,然后将该行的值写入该文件。