if (mysqli_connect_errno())
  echo "Failed to connect to MySQL: " . mysqli_connect_error();

echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";  
echo "<tr style='font-weight: bold;'>";  
echo "<td width='200' align='center'>Customer</td><td width='200' align='center'>Amount</td>";  
echo "</tr>";  

$custype = $_POST['custype'];

$from = $_POST['from'];

$to = $_POST['to'];
echo "<br><br>";
echo " <h2> Grand Total of ".$_POST['custype']. " from " .$_POST['from']. " to " .$_POST['to']. "</h2>";
$result = mysqli_query($con,"SELECT custype,SUM(amt) FROM cust WHERE custype = '$custype' AND DATE(day) >='$from' AND DATE(day) <='$to'");

echo "<tr>";  
echo "<td align='center' width='200'>" . $row['custype'] . "</td>";  
echo "<td align='center' width='200'>" . $row[1] . "</td>";  

echo "</tr>";  

echo "</table>";  


am new to php nd need to export the result printed to a csv file.. pls help