0

Following is my sql query to get data from mysql database. So how do i save it as .csv file ?

<?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
?>

It's showing following data column

Email | Pcode | Quote | type | House | type | B | Ba | P | Value | Date | Listed | Status

Babu
  • 455
  • 2
  • 14
  • 33
  • http://stackoverflow.com/questions/125113/php-code-to-convert-a-mysql-query-to-csv – The Alpha Mar 03 '14 at 07:18
  • @SheikhHeera I saw your link. It's showing a single query without while statement. In my query you see that there 2 while statement. So how do i use it ? – Babu Mar 03 '14 at 07:27
  • There are so many like this, http://stackoverflow.com/questions/356578/how-to-output-mysql-query-results-in-csv-format?rq=1, just search on Google. – The Alpha Mar 03 '14 at 07:34

0 Answers0