PHP生成excel并向其输入数据(2)
index2.php ?php $collection_contract_id=; $channel_name=; function check_text($text) { if(isset($_REQUEST[$text])) { return $_REQUEST[$text]; } } include_once 'smarty_inc.php'; $sql=select * from c
index2.php
<?php
$collection_contract_id="";
$channel_name="";
function check_text($text)
{
if(isset($_REQUEST[$text]))
{
return $_REQUEST[$text];
}
}
include_once 'smarty_inc.php';
$sql="select * from channel_accounts where ";
if(isset($_GET["time2"])&&$_GET["time2"]!="")
{
$collection_contract_id=$_GET["time2"];
if(!preg_match("/^[A-Za-z0-9]+$/", $collection_contract_id))
{
echo "<script>alert('收款合同号输入不合法!');</script>";
$smarty->display("index2.html");
exit();
}
$sql.=" collection_contract_id='".$collection_contract_id."' and ";
}
if(isset($_GET["key"])&&$_GET["key"]!="")
{
$channel_name=$_GET["key"];
if($channel_name=="")
{
echo "<script>alert('渠道名称输入不合法!');</script>";
$smarty->display("index2.html");
exit();
}
$sql.=" channel_name='".$channel_name."' and ";
}
$sql.=" 1=1 ";
//分页
if (isset($_GET['page']) && $_GET['page'] > 0)
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
$eachPages = 10;
$url = $_SERVER['PHP_SELF'];
$sql2 = "SELECT count(*) as total FROM (".$sql.") as a";
$result = mysql_query($sql2);
list($rowNums) = mysql_fetch_row($result);
$pageNums = ceil($rowNums / $eachPages);
$rowFrom = ($page > 1) ? (($page - 1) * $eachPages) : 0;
$sql2 = "".$sql." LIMIT ".$rowFrom.",".$eachPages."";
$result = mysql_query($sql2);
//------分页结束-------
//显示数据
$_SESSION["excel"]=$sql;
$result=mysql_query($sql2);
$outpagelist="";//输出数据的变量
while($out=mysql_fetch_array($result))
{
$outpagelist.="<tr>";
$outpagelist.="<td>".$out['collection_contract_id']."</td>";
$outpagelist.="<td>".$out['channel_name']."</td>";
$outpagelist.="<td>".$out['channel_money']."</td>";
$outpagelist.="<td>".$out['add_channel_cost']."</td>";
$outpagelist.="<td>".$out['add_channel_change_cost']."</td>";
$outpagelist.="<td>".$out['add_accounts']."</td>";
$outpagelist.="<td>".$out['add_back_money']."</td>";
$outpagelist.="<td>".$out['add_noback_money']."</td>";
$outpagelist.="<td>".$out['month_channel_money']."</td>";
$outpagelist.="<td>".$out['month_channel_cost']."</td>";
$outpagelist.="<td>".$out['month_channel_change_cost']."</td>";
$outpagelist.="<td>".$out['month_accounts']."</td>";
$outpagelist.="<td>".$out['month_back_money']."</td>";
$outpagelist.="<td>".$out['month_noback_money']."</td>";
$outpagelist.="</tr>";
}
//记录的总条数
// $sql_total_number="select * from channel_accounts";
$query=mysql_query($sql);
$num=mysql_num_rows($query);
//----------显示Page导航----------
$tablefoot="";
$tablefoot.= "<table>";
$tablefoot.='<tr><td>记录共有:'.$num. '条</td><td>';
$tablefoot.= ($page == 1) ? '首页' : '<a href="'.$url.'?page=1">'.'首页'.'</a>';
$tablefoot.= ' ';
$tablefoot.= ($page == 1) ? '上一页' : '<a href="'.$url.'?page=' . ($page - 1) . '&channel_name='.$channel_name.'&collection_contract_id='.$collection_contract_id.'" >'.'上一页' .'</a>';
$tablefoot.= ' ';
$tablefoot.= ($page == $pageNums) ? '下一页' : '<a href="'.$url.'?page='. ($page + 1) . '&channel_name='.$channel_name.'&collection_contract_id='.$collection_contract_id.'" >'.'下一页' .'</a>';
$tablefoot.= ' ';
$tablefoot.= ($page == $pageNums) ? '尾页' : '<a href="'.$url.'?page='.$pageNums.'&channel_name='.$channel_name.'&collection_contract_id='.$collection_contract_id.'">'.'尾页' .'</a>';
$tablefoot.= '</td></tr></table>';
if($pageNums==0)
{
$page=0;
$tablefoot="";
}
//------结束-------
$smarty->assign("tablefoot",$tablefoot);
$smarty->assign("time2_value",check_text("time2"));
$smarty->assign("key_value",check_text("key"));
$smarty->assign("outpagelist",$outpagelist);
$smarty->display("index2.html");
?>
精彩图集
精彩文章






