方维js方法:
function export_csv()
{
var inputs = $(".search_row").find("input:[type!='checkbox']");
var checkboxs = $(".search_row").find("input:[type='checkbox']:checked");
var selects = $(".search_row").find("select");
var param = '';
for(i=0;i<inputs.length;i++)
{
if(inputs[i].name!='m'&&inputs[i].name!='a')
param += "&"+inputs[i].name+"="+$(inputs[i]).val();
}
for(i=0;i<checkboxs.length;i++)
{
param += "&"+checkboxs[i].name+"="+$(checkboxs[i]).val();
}
for(i=0;i<selects.length;i++)
{
param += "&"+selects[i].name+"="+$(selects[i]).val();
}
var url= ROOT+"?"+VAR_MODULE+"="+MODULE_NAME+"&"+VAR_ACTION+"=export_csv";
alert(url);
location.href = url+param;
}
php 写法:
if($page == 1)
$content = iconv("utf-8","utf-8","编号,部门,姓名,手机,所属角色,提成系数(%),投资人人数,可以用余额,状态,最后登录时间,最后登录IP");
if($page==1)
$content = $content . "\n";
foreach($list as $k=>$v)
{
$export_value['id'] = iconv('utf-8','utf-8','"' . $v['id'] . '"');
$export_value['name'] = iconv('utf-8','utf-8','"' . $v['adm_name'] . '"');
$export_value['real_name'] = iconv('utf-8','utf-8','"' . $v['real_name'] . '"');
$export_value['mobile'] = iconv('utf-8','utf-8','"' . $v['mobile'] . '"');
$export_value['role'] = iconv('utf-8','utf-8','"' . M("Role")->where("id=".$v['role_id'])->getField("name") . '"');
$export_value['rate'] = iconv('utf-8','utf-8','"' . $v['referrals_rate'] . '"');
$export_value['rcount'] = iconv('utf-8','utf-8','"' . $v['referrals_count'] . '"');
$export_value['money'] = iconv('utf-8','utf-8','"' . $v['referrals_money'] . '"');
$export_value['status'] = iconv('utf-8','utf-8','"' . ($v['is_effect']== 1 ? "有效": "无效") . '"');
$export_value['time'] = iconv('utf-8','utf-8','"' . to_date($v['login_time']) . '"');
$export_value['ip'] = iconv('utf-8','utf-8','"' . $v['login_ip'] . '"');
$content .= implode(",", $export_value) . "\n";
}
header("Content-Disposition: attachment; filename=部门.csv");
echo $content;