解决方案 »
- PHP中require PK require_once, 构建自己的高效require_once(10倍的性能提升)
- input框内输入内容,怎么实现回车后自动搜索数据库返回其他input框的内容
- php文件需要帮助?
- 分页的一个问题,百思不得其解
- 招PHP程序员,上海光大会展
- 急!!!有人知道“Odysseus”这个工具吗?
- 请教: 树遍历问题 [**算法高手请进**]
- php5异常处理的不明白的地方
- 再请教一个关于日期问题,请大家帮帮忙啊
- 哪位兄弟有这个系统的PHP代码啊!!!! 要多少分给多少分
- MySQL中连接各个表的连接属性怎么在语句中实现,是不是还得再创建一个表
- 关于【PHP发送邮件】的问题
一切可被 php 见到的客户端信息,都是客户端发送的
如果是用户(客户端)输入,服务器的CPU计算,那要有一个传输过程(提交)
客户端不能执行php的,或者说到了客户端就不是一个php了,只是html
我这个php方法是通过页面上输入框的值动态生成datagrid的列的。 这样的情况该怎么解决参数传递的问题?
当然你可以使用 jquery 框架,他众多的插件足以满足应用需求
......
}这个方法实现的供全部用js代码重新写,还是用js或者jquery获得页面元素的值传递到方法中?
<?php
$btime= "<script>document.write(betime)</script>";
$etime="<script>document.write(endtime)</script>";
//echo $btime."***--".$etime;//输出 '2013-12'***'2014-02'
initRows1($btime, $etime);//同样的参数输出却不正确
//initRows1('2013-12', '2014-02');//initRows1方法正确输出
?>
方法代码
function initRows1($bym,$eym){
//echo $bym."^^^^^".$eym."<br>";
//判断两个日期间相差多少月
$bym_list=explode("-",$bym);
$eym_list=explode("-",$eym);
if($bym_list[0]==$eym_list[0]){
$months=abs($bym_list[1]-$eym_list[1]);
}else{
$months=abs(($eym_list[0]-$bym_list[0]-1)*12)+abs($eym_list[1]+(12-$bym_list[1]));
}
echo $bym."^---^".$eym."<br>";
$items=array();
for ($i=0;$i<=$months;$i++){
echo "xxxx ".$i."--".date("Y-m",strtotime("+$i months",strtotime($bym)))."****".$bym."<br>";
//echo substr(getMonth(date("Y-m",strtotime("+$i months",strtotime($bym)))),-4)."---";
echo "<th colspan='3'><strong>".substr(getMonth(date("Y-m",strtotime("+$i months",strtotime($bym)))),-4).substr(getMonth(date("Y-m",strtotime("+$i months",strtotime($bym)))),0,-4)."</strong></th>";
}}
页面输出关键是这一句
echo "xxxx ".$i."--".date("Y-m",strtotime("+$i months",strtotime($bym)))."****".$bym."<br>";
其中$bym明明是2013-12但是date("Y-m",strtotime("+$i months",strtotime($bym)))输出却是1970-01。怎么回事?
需 strtotime($bym .'01') 才可以date("Y-m",strtotime("+$i months",strtotime($bym)))
写作
date("Y-m", strtotime("+$i months $bym-01"))
是不是更清晰点呢?
//initRows1('2013-12', '2014-02');//initRows1方法正确输出
function initRows1($bym,$eym){ //判断两个日期间相差多少月
$bym_list=explode("-",$bym);
$eym_list=explode("-",$eym);
if($bym_list[0]==$eym_list[0]){
$months=abs($bym_list[1]-$eym_list[1]);
}else{
$months=abs(($eym_list[0]-$bym_list[0]-1)*12)+abs($eym_list[1]+(12-$bym_list[1]));
}
echo $bym."^---^".$eym."yyy".$months."<br>";
$items=array();
for ($i=0;$i<=$months;$i++){
echo "xxxx ".$i."--".date("Y-m",strtotime("+$i months",strtotime($bym.'01')))."****".$bym."<br>";
echo "<th colspan='3'><strong>".substr(getMonth(date("Y-m", strtotime("+$i months $bym-01"))),-4).substr(getMonth(date("Y-m", strtotime("+$i months $bym-01"))),0,-4)."</strong></th>";
}}
当用initRows1('2013-12', '2014-02');//initRows1方法正确输出当用//echo $btime."***--".$etime;//输出 '2013-12'***'2014-02'
initRows1($btime, $etime);//同样的参数输出却不正确为什么会这样??
function initRows1($bym,$eym){
//判断两个日期间相差多少月
$bym_list=explode("-",$bym);
$eym_list=explode("-",$eym);
if($bym_list[0]==$eym_list[0]){
$months=abs($bym_list[1]-$eym_list[1]);
}else{
$months=abs(($eym_list[0]-$bym_list[0]-1)*12)+abs($eym_list[1]+(12-$bym_list[1]));
}
echo $bym."^---^".$eym."yyy".$months."<br>";
$items=array();
for ($i=0;$i<=$months;$i++){
echo "xxxx ".$i."--".date("Y-m",strtotime("+$i months",strtotime($bym.'01')))."****".$bym."<br>";
echo "<th colspan='3'><strong>".substr(getMonth(date("Y-m", strtotime("+$i months $bym-01"))),-4).substr(getMonth(date("Y-m", strtotime("+$i months $bym-01"))),0,-4)."</strong></th>";
}
}注意这算相差了多少个月的方法,同样的参数进去出来了不同结果
//$btime=date('Y-m-d',strtotime($btime."-01"));//1970-01
//$etime=date('Y-m-d',strtotime($etime."-01"));//1970-01
//$btime=strtotime($btime."-01");//1970-01
//$etime=strtotime($etime."-01");
$btime=date('Y-m',strtotime($btime));//1970-01
$etime=date('Y-m',strtotime($etime));
echo $btime."--**--".$etime."<br>";//
‘2013-12’怎么转化为date格式的‘2013-12’?
$btime = '2013-12';
echo $btime = date('Y-m',strtotime($btime));//2013-12php 5.4 之前
$btime = '2013-12';
echo $btime = date('Y-m',strtotime("$btime-01"));//2013-12
<?php$btime= "<script>document.write(betime1)</script>";
$etime="<script>document.write(endtime1)</script>";
$x=$btime;
echo $btime."<br>";//2013-12
if(is_object($btime)){
echo "----";
}else{
echo "bbb";
if(is_string($x)){
echo "iii";
}else{
echo "kkk";
}
}
if($x=='2013-12'){//不相等
echo "xxx<br>";
}
echo "strtotime:".strtotime("$x-01")."<br>";//输出空
echo date('Y-m',strtotime("$btime-01"));//1970-01initRows1('2013-12', '2014-02');//initRows1方法正确输出
//initRows1($btime,$etime);
//$btime="<script>document.getElementById('bt').value</script>";
//$etime="<script>document.getElementById('et').value</script>";
//echo $btime."-输入-".$etime."<br>";//输出 '2013-12'***'2014-02'
//$btime=date('Y-m-d',strtotime($btime."-01"));//1970-01
//$etime=date('Y-m-d',strtotime($etime."-01"));//1970-01
//$btime=strtotime($btime."-01");//1970-01
//$etime=strtotime($etime."-01");
//$btime=strtotime($btime);//空
//$etime=strtotime($etime);
//echo $etime."^^^".$btime."<br>";
//$etime=date('Y-m',strtotime($etime));
//$btime=date('Y-m',strtotime($btime));
//echo $btime = date('Y-m',strtotime($btime));//1970-01
//$btime = date('Y-m',strtotime("$btime-01"));////1970-01
//echo $btime."--**--".$etime."<br>";// //$btime=(int)$btime;
//$etime=(int)$etime;
//$bt=date("Y-m",strtotime("-3 month"));
//$et=date("Y-m",strtotime("-1 month"));
//$x=date('Y-m',strtotime($btime));;
//$y=date('Y-m',strtotime($etime));;
//echo "test".strtotime("$btime.-01")."<br>";
//echo $etime."***".$btime."---".$x."&&&".$y."<br>";//initRows1(date("Y-m",strtotime("-3 month")), date("Y-m",strtotime("-1 month")));//同样的参数输出却不正确 //initRows1('2013-12', '2014-02');//initRows1方法正确输出
?>
echo "$bym,$eym<br>"; //加上这句,看看传入的都是什么
//判断两个日期间相差多少月观察你注释掉的代码,你根本就没有从客户端取到数据
我是用js获取的上元素的值,在传给本页面对应的php,功能是在easyui datagrid上实现动态加载列,根据用户选择的不同时间段对应生成不同的列,代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>salesquantityper</title>
<link rel="stylesheet" type="text/css" href="http://www.java1234.com/jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="http://www.java1234.com/jquery-easyui-1.3.3/themes/icon.css">
<link rel="stylesheet" type="text/css" href="http://www.java1234.com/jquery-easyui-1.3.3/demo/demo.css">
<script type="text/javascript" src="http://www.java1234.com/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="http://www.java1234.com/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="http://www.java1234.com/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<style type="text/css">
.box{position:relative;}
.tip{position:absolute;border:2px solid #000;}
</style>
</head>
<body>
<!-- 级联菜单 -->
<!-- 筛选列表 -->
<div style="background-color:EFF7FB">
<form id="form1" style="margin-bottom:0px;" action="get_bestlist.php">
<table>
<tr>
<td><h4>Search:</h4></td>
<td><input class="easyui-datebox" id="bt" name="bt" value=<?php
$bt=date("Y-m",strtotime("-3 month"));
$et=date("Y-m",strtotime("-1 month"));
echo $bt;
?>></input></td><td>--to--</td>
<td><input id="et" name="et" class="easyui-datebox" value=<?php
echo $et;
?>></td>
<td> Resgion: <select id="area" name="area" class="easyui-combobox" name="area" data-options=" multiple:true" onchange="areaChanged(this.value)" style="width:150px;">
<option value="'E','N','H','S','C','W','F'">All Region</option>
<option value="'E'">East</option>
<option value="'N'">North</option>
<option value="'H'">Center</option>
<option value="'S'">South</option>
<option value="'C'">NorthEast</option>
<option value="'W'">Western</option>
<option value="'F'">Distribution area</option>
</select>
</td>
<td>Category: <select id="level" class="easyui-combobox" name="level" data-options=" multiple:true" style="width:150px;">
<option value="'A+','A-','A','B','C','D'">All Level</option>
<option value="'A+','A-','A'">A</option>
<option value="'B'">B</option>
<option value="'C'">C</option>
<option value="'D'">D</option>
<option value="'OUTLETS'">OUTLETS</option>
</select>
</td> <TD><input type="button" id="but" value="go" ></TD>
</tr>
</table>
</form> <br>
<div><p>Default show the data of last 3 months</p> </div> </div>
<br>
<script >
//alert($('#bt').datebox('getValue'));
var betime1=document.getElementById('bt').value;
var endtime1=document.getElementById('et').value;//var xx="kokjh";
jQuery(document).ready(function(){
//var betime=$('#bt').datebox('getValue');
//var endtime=$('#et').datebox('getValue');
$('#but').click(function(){
//alert($('#bt').datebox('getValue')+"***"+$('#et').datebox('getValue'));
$('#salesquantityper').datagrid('reload',{area:$('#area').combobox('getValues'),level:$('#level').combobox('getValues'),bt:$('#bt').datebox('getValue'),et:$('#et').datebox('getValue')});
});});
</script>
<!-- bestline表格 -->
<?php
//"<script>document.write(betime)</script>", "<script>document.write(betime)</script>"
//echo "<script>document.write(betime)</script><br>";
//echo "<script>document.write(endtime)</script><br>";//月份的英文转换
function getMonth($str_ym){
//echo "<br>getmonth".$str_ym."<br>";
$ym_list=explode("-",$str_ym);
$yy.=$ym_list[0];
$mm=$ym_list[1];
switch ($mm) {
case 01 :
return "January".$yy;
break;
case 02:
return "February".$yy;
break;
case 03 :
return "March".$yy;
break;
case 04 :
return "April".$yy;
break;
case 05:
return "May".$yy;
break;
case 06 :
return "June".$yy;
break;
case 07 :
return "July".$yy;
break;
case 08 :
return "Aguest".$yy;
break;
case 09 :
return "September".$yy;
break;
case 10:
return "October".$yy;
break;
case 11 :
return "November".$yy;
break;
case 12 :
return "December".$yy;
break;}
}//生成列function xx1($str1){
$strt=substr($str1,0,4).'-';
return $strt.substr($str1,4,6);
}
function initRows1($bym,$eym){
echo "^^^^^^^^^$bym,$eym<br>"; //加上这句,看看传入的都是什么
//判断两个日期间相差多少月
$bym_list=explode("-",$bym);
$eym_list=explode("-",$eym);
if($bym_list[0]==$eym_list[0]){
$months=abs($bym_list[1]-$eym_list[1]);
}else{
$months=abs(($eym_list[0]-$bym_list[0]-1)*12)+abs($eym_list[1]+(12-$bym_list[1]));
}
// echo $bym."^---^".$eym."yyy".$months."<br>";
$items=array();
for ($i=0;$i<=$months;$i++){
// echo "xxxx ".$i."--".date("Y-m",strtotime("+$i months",strtotime($bym.'-01')))."****".$bym."<br>";
echo "<th colspan='3'><strong>".substr(getMonth(date("Y-m", strtotime("+$i months $bym"))),-4).substr(getMonth(date("Y-m", strtotime("+$i months $bym"))),0,-4)."</strong></th>";
}}function initRows2($bym,$eym){
//判断两个日期间相差多少月
$bym_list=explode("-",$bym);
$eym_list=explode("-",$eym);
if($bym_list[0]==$eym_list[0]){
$months=abs($bym_list[1]-$eym_list[1]);
}else{
$months=abs(($eym_list[0]-$bym_list[0]-1)*12)+abs($eym_list[1]+(12-$bym_list[1]));
} $items=array();
for ($i=0;$i<=$months;$i++){
echo"<th data-options=field:'".getMonth(date("Y-m", strtotime("+$i months $bym-01")))."_Number_stores' width='80' align='right'><strong>Nubmer of<br> Stores</strong></th>";
echo"<th field='".getMonth(date("Y-m", strtotime("+$i months $bym-01")))."_Quantity_sold' width='100' align='right'><strong>Quantity Sold</strong></th>";
echo"<th field='".getMonth(date("Y-m", strtotime("+$i months $bym-01")))."_qn' width='120' align='right'><strong>Average qty <br>Sold per store</strong></th>";
}}?>
<table id="salesquantityper" class="easyui-datagrid" style="width:auto;height:220px" title="Stores sales quantity performance"
data-options="url: 'get_salesquantityper.php', singleSelect: true, rownumbers:true "
>
<thead data-options="frozen:true">
<tr>
<th data-options="field:'Category'" width="100" ><strong>Category</strong></th>
</tr>
</thead>
<thead >
<tr>
<?php$btime= "<script>document.write(betime1)</script>";
$etime="<script>document.write(endtime1)</script>";
$x=$btime;
echo $btime."<br>";//2013-12
if(is_object($btime)){
echo "----";
}else{
echo "bbb";
if(is_string($x)){
echo "iii";//输出
}else{
echo "kkk";
}
}
if($x=='2013-12'){//不相等
echo "xxx<br>";
}
echo "strtotime:".strtotime("$x-01")."<br>";//输出空
echo date('Y-m',strtotime("$btime-01"));//1970-01//initRows1('2013-12', '2014-02');//initRows1方法正确输出
initRows1($btime,$etime);
//$btime="<script>document.getElementById('bt').value</script>";
//$etime="<script>document.getElementById('et').value</script>";
//echo $btime."-输入-".$etime."<br>";//输出 '2013-12'***'2014-02'
//$btime=date('Y-m-d',strtotime($btime."-01"));//1970-01
//$etime=date('Y-m-d',strtotime($etime."-01"));//1970-01
//$btime=strtotime($btime."-01");//1970-01
//$etime=strtotime($etime."-01");
//$btime=strtotime($btime);//空
//$etime=strtotime($etime);
//echo $etime."^^^".$btime."<br>";
//$etime=date('Y-m',strtotime($etime));
//$btime=date('Y-m',strtotime($btime));
//echo $btime = date('Y-m',strtotime($btime));//1970-01
//$btime = date('Y-m',strtotime("$btime-01"));////1970-01
//echo $btime."--**--".$etime."<br>";// //$btime=(int)$btime;
//$etime=(int)$etime;
//$bt=date("Y-m",strtotime("-3 month"));
//$et=date("Y-m",strtotime("-1 month"));
//$x=date('Y-m',strtotime($btime));;
//$y=date('Y-m',strtotime($etime));;
//echo "test".strtotime("$btime.-01")."<br>";
//echo $etime."***".$btime."---".$x."&&&".$y."<br>";//initRows1(date("Y-m",strtotime("-3 month")), date("Y-m",strtotime("-1 month")));//同样的参数输出却不正确 //initRows1('2013-12', '2014-02');//initRows1方法正确输出
?>
</tr>
<tr>
<?php //echo $btime."***".$etime;//输出 '2013-12'***'2014-02'
//initRows2($btime, $etime);
initRows2('2013-12', '2014-02');
?>
</tr>
</thead>
</table></body>
</html>
$etime="<script>document.write(endtime1)</script>";
initRows1($btime,$etime);
这能对吗?
能正确输出值....那该怎么改呢?