<?php  
$con=mysqli_connect("localhost","root","","trial");

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>";  
if(isset($_POST['submit']))
{

$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'");

while($row=mysqli_fetch_array($result))  
{  
echo "<tr>";  
echo "<td align='center' width='200'>" . $row['custype'] . "</td>";  
echo "<td align='center' width='200'>" . $row[1] . "</td>";  

echo "</tr>";  
} 

echo "</table>";  

}
mysqli_close($con);
?>  

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

I guess you should check out the fputcsv() function :).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.