PHP Export data to CSV file

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags application comment community contact person csv data default export

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 ' &nbsp; ';
 }
 
  $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;
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.