PHP Tutorial Export data to CSV file
Include (". /admin/inc/inc.php ");
$times = time ();
$filename = $times. " CSV ";
$a = "contact person, telephone number, community, required materials, notes, application time n";
$days = Postget ("Days");
$mktime = Daystomktime ($days);
$sql = "SELECT * from Tugou where ($times-times) < $mktime";
$db = new db ();
$result = $db->query ($sql);
$rs = $db->fetch ($result, 0);
foreach ($rs as $v => $vv)
{
$a. = $vv [' name ']. $VV [' Mo ']. $VV [' Comm '].
Commbox ($vv [' Cbox ']). ",";
$a. = "". $vv [' Bak ']. Date (' y-m-d ', $vv [' Times ']). "RN
";
}
echo $a;
$hod = fopen ($filename, "w+");
if (fwrite ($hod, $a))
{
echo "Generated the file successfully, click <a href= $filename target=_blank> download Excel
Document </a> ";
}
function Daystomktime ($days)
{
Switch ($days)
{
Case 1:
$t = 86400;
Break;
Case 7:
$t = 86400*7;
Break;
Case 30:
$t = 86400*30;
Break;
Case 90:
$t = 86400*90;
Break;
Case 2048:
$t = 86400*2048;
Break;
}
return $t;
}
Function Commbox ($ars)
{
if (trim ($ars) = = ")
{
return ' ';
}
$array = include ("tugou.php");
$tmp = explode (', ', $ars);
$str = ';
if ($tmp)
{
foreach ($tmp as $c)
{
$str. = $array [Intval ($c)]. ' |
}
}
return $str;
}
/*
struct
create table if not exists ' Tugou ' (
' id ' int (8) is not NULL auto_increment,
' name ' varchar () default NULL comment ' names ',
' mo ' varchar () default NULL comment ' mobile ',
' Comm ' varchar default NULL,
' bak ' varchar (+) default NULL comment ' backup ',
' cbox ' varchar (500) Default NULL comment ' type ',
' Times ' int (4) default NULL,
' IP ' varchar default NULL,
Primary key (' id ')
) ENGINE=INNODB&NBSp; Default Charset=utf8 auto_increment=8;