Hi,
From my code below, I want to export & download the search results into a csv file. The output should look like this: Column A of the CSV FIle
cascadium
the results of $row1[‘size’]
the results of $num1
the results of $median1
Could you show me the code to achieve this please? Thanks a lot.
<?php
include("/path/to/my/website/public_html/connect_to_the_database.php");
$query6=mysql_query("SELECT size, COUNT(size) as fcount FROM condo WHERE (location LIKE '%cascadium%') AND (sale_rent LIKE '%rent%') AND (size > 0) GROUP BY size ORDER BY fcount DESC LIMIT 1");
$row1=@mysql_fetch_array($query6);
$query1=mysql_query("SELECT price FROM condo WHERE (location LIKE '%cascadium%') AND (sale_rent LIKE '%rent%') AND (size = {$row1['size']}) AND (price > 0) ORDER BY price DESC");
//median calculation
$thearray=array();
while ( $row=@mysql_fetch_array($query1,MYSQL_NUM) ) {
$thearray[]=$row[0];
}
$num0=count($thearray);
if ($num0 % 2) {
$median1 = $thearray[floor($num0+1)/2 - 1];
} else {
$median1 = ($thearray[$num0/2] + $thearray[$num0/2 - 1]) / 2;
}
$num1=@mysql_num_rows($query1);
echo "<p><strong>Keyword: </strong>".cascadium."<br/>";
echo "<strong>Most Common Land / Built-up Area: </strong>".$row1['size']."sq ft <br/>";
echo "<strong>Total Samples Analysed: </strong>".$num1."<br/>";
echo "<strong>Median Asking Price: </strong> RM".$median1."<br/></p>";
?>
$record is your 4 fields (values) concatenated together with comma separators. In case the values may themselves include commas it would be safest to enclose each value between double-quotes:
My next question is, how do I automatically download this csv file without having to click any additional hyperlink or button? Explained slightly differently, I want the data to be written to the csv file & I want the csv file to download immediately.