如何将查询结果保存为.csv文件?

时间:2014-03-03 07:15:10

标签: php mysql

以下是我从sql查询从mysql数据库获取数据。那么如何将其保存为.csv文件?

<?php
$sqlagentdetails = "select * from users WHERE company_name != ''";
$rowresult = mysql_query($sqlagentdetails); 
while($row = mysql_fetch_array($rowresult, MYSQL_ASSOC)){
    $pc1 = $row['pc1'];
    $pc2 = $row['pc2'];
    $pc3 = $row['pc3'];
    $pc4 = $row['pc4'];                      
    $emailAgent = $row['user_email'];                      
    $user_id = $row['id'];

$myQuery =  mysql_query("
 SELECT * 
   FROM user_property upr 
  WHERE (postcode = '$pc1' OR
         postcode = '$pc2' OR
         postcode = '$pc3' OR
         postcode = '$pc4') AND
         datediff(CURDATE(), upr.creation_date) <= 7 AND
         NOT EXISTS(SELECT ofr.property_id 
                      FROM offers ofr 
                     WHERE ofr.property_id = upr.property_id AND
                           ofr.agent_id IN(SELECT id 
                                             FROM users 
                                            WHERE company_name !=''
                                          )
                   )
ORDER BY property_id DESC");
$num =  mysql_num_rows($myQuery);
while($row = mysql_fetch_array($myQuery)){  

    /// data is showing here............

    }// second while statement

}// first while statement
?>

它显示以下数据列

电子邮件| Pcode |引用|类型|房子|类型| B | Ba | P |价值|日期|上市|状态

0 个答案:

没有答案