<?php
require_once("../../common/connect.php");

$contents="S.No, Firm Name, Contact Person, address, State, Local City, City, Mobile, Email, ICAP Code\n";

//Mysql query to get records from datanbase
//You can customize the query to filter from particular date and month etc...Which will depends your database structure.
$user_query = mysql_query("SELECT * FROM  `icap_partner` WHERE  `state` ='$_GET[id]' ORDER BY  `icap_partner`.`id` ASC");
$count=0;

$GetState=mysql_query("SELECT * FROM  `state` WHERE  `ids` ='$_GET[id]'");
$GetState1=mysql_fetch_assoc($GetState);


//While loop to fetch the records
while($row = mysql_fetch_assoc($user_query))
{
$GetCity=mysql_query("SELECT * FROM  `city` WHERE  `city_id` ='$row[city]'");
$GetCity1=mysql_fetch_assoc($GetCity);

$count+=1;
$t=$row['time'];

//$GetCourse=mysql_query("SELECT * FROM `course` WHERE `course_id` ='$row[course]'");
//$GetCourse1=mysql_fetch_assoc($GetCourse);
$GetCourse2= $row['address'];
$GetCourse3=str_replace(","," ", $GetCourse2);

$contents.=$count.",";
$contents.=$row['firm_name'].",";
$contents.=$row['contact_person'].",";
$contents.=$GetCourse3.",";
$contents.=$GetState1['state'].",";
$contents.=$row['local_city'].",";
$contents.=$GetCity1['cityname'].",";
$contents.=$row['mobile'].",";
$contents.=$row['email'].",";
$contents.=$row['icap_code']."\n";
}

$contents = strip_tags($contents); 

header("Content-Disposition: attachment; filename=icap-data.csv");
print $contents;

?>