写在前面
php:超文本预处理器,一种通用开源脚本语言文件
这是首次接触PHP相关项目,此前没有学过或接触过PHP相关内容。赶鸭子上架了,所以内容较为简单,仅此记录。
(前后端在一起)
简单格式
<?php
require('head.php');
require ("lib_SysLog.php"); // 页面包含其他文件时的写法
$page = $_GET['page']; // 页面接受get请求的参数
$items_per_page = 20; // 页面定义变量
$user_id=$_SESSION["id"];
$user_name=$_SESSION["name"]; // 页面获取session中的对象值
$sql = "select * from table"; // 页面直接写sql语句
$result=mysql_query($sql)or die("无效查询: " . mysql_error()); //执行sql语句查询
?>
<html>
<script src="include/My97DatePicker/WdatePicker.js"></script> //引入时间插件
<script>
//按到期日期查找
function date_search() {
var daoqiriqi_begin=document.getElementById("daoqiriqi_begin").value;
var daoqiriqi_end=document.getElementById("daoqiriqi_end").value;
window.location.href="dianpiao_list.php?daoqiriqi_begin="+daoqiriqi_begin+"&daoqiriqi_end="+daoqiriqi_end;
//get请求,拼接get参数
}
// 按抬头公司名 查询
function tai_tou_search() {
var gs=document.getElementById("taitou").value;
<?php if (output_rule()=="dianpiao_list.php"){
?>
window.location.href="<?php echo output_rule();?>?tai_tou_gong_si="+gs;
<?php
}else{
?>
window.location.href = "<?php echo output_rule();?>&tai_tou_gong_si=" + gs;
<?php
}?>
/*
* * js中穿插php代码
*/
}
</script>
<body>
<div>
<div style="display: flow; margin: 15px auto;">
到期日期范围从:
<input style="width: 150px;height: 20px" id="daoqiriqi_begin" value="<?php echo $daoqiriqi_begin?>" name="daoqiriqi" type="text" class="order_input Wdate" onclick="WdatePicker({lang:'zh-cn'})"/>
<!-- 此处用到时间插件 -->
至
<input style="width: 150px;height: 20px" id="daoqiriqi_end" value="<?php echo $daoqiriqi_end?>" name="daoqiriqi" type="text" class="order_input Wdate" onclick="WdatePicker({lang:'zh-cn'})"/>
<input type="submit" onclick="date_search()" value="搜索">
</div>
</div>
<table style="font-size: 12px;width: 1500px;text-align: center;margin: 10px">
<tr>
<td style="padding: 5px;">序号</td>
<td>
<select name="taitou" id="taitou" style="width: 157px; height: 23px;" onchange="tai_tou_search()">
<option <?php if ($tai_tou=="")echo "selected=\"selected\"" ?> value="">公司抬头</option>
<option <?php if ($tai_tou=='ty')echo "selected=\"selected\"" ?> value="ty">ty</option>
<option <?php if ($tai_tou=='jb')echo "selected=\"selected\"" ?> value="jb">jb</option>
<option <?php if ($tai_tou=='sd')echo "selected=\"selected\"" ?> value="sd">sd</option>
<option <?php if ($tai_tou=='sdf')echo "selected=\"selected\"" ?> value="sdf">sdf</option>
<option <?php if ($tai_tou=='dl')echo "selected=\"selected\"" ?> value="dl">dl</option>
<option <?php if ($tai_tou=='shty')echo "selected=\"selected\"" ?> value="shty">shty</option>
<option <?php if ($tai_tou=='jn')echo "selected=\"selected\"" ?> value="jn">jn</option>
</select>
</td>
<td style="padding: 5px;">签收日期</td>
<td style="padding: 5px;">到期日期</td>
<td>
<?php
if($order == "desc"){
?>
<button id="order_desc" onclick="order_search('desc')" value="desc">升</button>
<?php
}else{
?>
<button id="order_asc" onclick="order_search('asc')" value="asc">降</button>
<?php
}
?>
</td></tr>
<?php
$row = mysql_fetch_array($result); //从结果集中取得一行作为关联数组,或数字数组,或二者兼有
返回根据从结果集取得的行生成的数组,如果没有更多行则返回 false。
if( $row == false ){
?>
无数据
<?php
}else{
$i=1;
do{
?>
<tr >
<td style="padding: 5px;"><?php echo $i?></td>
<td style="padding: 5px;"><?php echo $row["tai_tou_gong_si"];?></td>
<td style="padding: 5px;"><?php echo date("Y-m-d",strtotime($row["chupiao_date"]))?></td>
<td style="padding: 5px;" colspan="2"><?php echo date("Y-m-d",strtotime($row["daoqi_date"]))?></td>
</tr>
<?php
$i++;
}while( $row = mysql_fetch_array($result) );
}
?>
</table>
</body>
</html>
仅记录简单代码格式,方便以后快速开启php学习。
文件下载
<span style="display: flow"><select onchange="show_Daochu()" name="" id='daochu_select' style="background-color:#ededed ;border: grey solid 1px;height: 25px;width: 80px">
<option value="0" selected hidden>导出</option>
<option value="zhuan_ru">导出在库电票</option>
<option value="yi_chuli">导出已处理电票</option>
</select></span>
<?php
require_once '../PHPExcel-1.8/Classes/PHPExcel.php';
header('Content-Type:text/html;Charset=utf-8;');
function dateFormat($date){
}
$user_name= $_GET['user_name'];
$user_id=$_GET['user_id'];
$id=$_GET["dpId"];
$type=$_GET["type"];
//$create_date=strtotime(date("Y-m-d H:i:s"));
$now_7 = date("Y-m-d", strtotime('-7days'));
$conn = mysql_connect("localhost","ecshop","eric0712") or die("不能连接数据库");
mysql_select_db("tycelec", $conn);
if ($type=="zhuan_ru"){
$sql="select * from oa_dianpiao WHERE is_valid=0 and state='".$type."'";
}
if ($type=="yi_chuli"){
$sql="select * from oa_dianpiao WHERE is_valid=0 and state!='zhuan_ru'";
}
//$sql="select * from oa_dianpiao WHERE state='".$type."'";
$result=mysql_query($sql);
$arr=mysql_fetch_array($result);
//创建对象
$objPHPExcel = new PHPExcel();
//设置文档的属性:
$objPHPExcel->getProperties()->setCreator($user_name)
->setLastModifiedBy($user_name)
->setTitle($id)
->setSubject("dianpiao Excel out")
->setDescription("Test document for PHPExcel, generated using PHP classes.")
->setKeywords("dianpiao")
->setCategory("dianpiao Excel out");
//单元格默认宽度
$objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(30);
//垂直居中
$objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
//设置填充的样式和背景色
$objPHPExcel->getActiveSheet()->getStyle( 'A1:Q1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle( 'A2:Q2')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle( 'A1:Q1')->getFill()->getStartColor()->setARGB('#FFEFDB');
$objPHPExcel->getActiveSheet()->getStyle( 'A2:Q2')->getFill()->getStartColor()->setARGB('#FFE7BA');
//合并单元格 添加表头
$objPHPExcel->getActiveSheet()->mergeCells('A1:Q1');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1',"电票");
$objPHPExcel->getActiveSheet()->getStyle( 'A1')->getFont()->setSize(20);
$objPHPExcel->getActiveSheet()->getStyle( 'A2:Q2')->getFont()->setSize(14);
// 給Excel表格增加数据:
$objPHPExcel->setActiveSheetIndex(0)
// ->setCellValue('A2', 'tai_tou_gong_si')
// ->setCellValue('B2', 'xiao_shou_ren_yuan')
// ->setCellValue('C2', 'chu_piao_ren')
// ->setCellValue('D2', 'cheng_dui_ren')
// ->setCellValue('E2', 'qian_shou')
// ->setCellValue('F2', 'chupiao_date')
// ->setCellValue('G2', 'daoqi_date')
// ->setCellValue('H2', 'piao_hao')
// ->setCellValue('I2', 'jin_e_xiaoxie')
// ->setCellValue('J2', 'jin_e_daxie')
// ->setCellValue('K2', 'qian_shou_date')
// ->setCellValue('L2', 'state')
// ->setCellValue('M2', 'state_to')
// ->setCellValue('N2', 'xingshi')
// ->setCellValue('O2', 'bank')
// ->setCellValue('P2', 'remark_1')
// ->setCellValue('Q2', 'remark_2')
// ->setCellValue('R2', 'remark_3')
// ->setCellValue('S2', 'create_date');
//
->setCellValue('A2', '抬头公司')
->setCellValue('B2', '销售人员')
->setCellValue('C2', '出票人')
->setCellValue('D2', '承兑人')
->setCellValue('E2', '前手')
->setCellValue('F2', '出票日期')
->setCellValue('G2', '到期日期')
->setCellValue('H2', '票号')
->setCellValue('I2', '金额小写')
->setCellValue('J2', '金额大写')
->setCellValue('K2', '签收日期')
->setCellValue('L2', '状态')
->setCellValue('M2', '转/找')
->setCellValue('N2', '形式')
->setCellValue('O2', '到账银行')
->setCellValue('P2', '备注')
->setCellValue('Q2', '创建时间');
if ($arr!=false){
$i=3;
do{
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.$i, $arr["tai_tou_gong_si"])
->setCellValue('B'.$i, $arr['xiao_shou_ren_yuan'])
->setCellValue('C'.$i, $arr["chu_piao_ren"])
->setCellValue('D'.$i, $arr["cheng_dui_ren"])
->setCellValue("E".$i,$arr["qian_shou"])
->setCellValue("F".$i,$arr["chupiao_date"])
->setCellValue("G".$i,$arr["daoqi_date"])
->setCellValue("H".$i,$arr["piao_hao"])
->setCellValue("I".$i,$arr["jin_e_xiaoxie"])
->setCellValue("J".$i,$arr["jin_e_daxie"])
->setCellValue("K".$i,$arr["qian_shou_date"])
->setCellValue("L".$i,$arr["state"])
->setCellValue("M".$i,$arr["state_to"])
->setCellValue("N".$i,$arr["xingshi"])
->setCellValue("O".$i,$arr["bank"])
->setCellValue("P".$i,$arr["remark_1"])
->setCellValue("Q".$i,$arr["create_date"]);
$i++;
}while($arr = mysql_fetch_array($result));
}
$objPHPExcel->getActiveSheet()->setTitle('2');
$objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: applicationnd.ms-excel');
header('Content-Disposition: attachment;filename='.$user_id."_".$user_name."_".$type.'.xls');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;