日历价格表?
现在效果如图:
代码如下:
class productDate{
var $product_id = '';
var $date = '';
var $original_date = '';
var $nextDate = '';
var $prices = '';
var $count = 42;
var $nowWeek;
var $nowMonth;
var $nextMonth;
var $startDate;
var $lastDate;
function create($product_id, $date, $prices){
$this->product_id = $product_id;
$this->original_date = $this->date = strtotime($date);
$this->prices = $prices;
$this->_init();
$datesTmp = array_keys($this->prices);
$this->lastDate = array_pop($datesTmp);
}
/**
* 下一个月
*
*/
function createNext(){
$this->nextDate = $date; //下一月, 待处理
$this->create($this->nextDate);
}
function getNextMonth($tmp_date, $step = 1){
//切割出年份
$tmp_year= date('Y', $tmp_date);
//切割出月份
$tmp_mon =date('m', $tmp_date);
$tmp_nextmonth=mktime(0,0,0,$tmp_mon + $step,1,$tmp_year);
//得到当前月的下2个月 ,最晚的日期的下一个月的开始
return $tmp_nextmonth;
}
function getPreMonth($tmp_date, $step = 1){
//切割出年份
$tmp_year= date('Y', $tmp_date);
//切割出月份
$tmp_mon =date('m', $tmp_date);
$tmp_premonth=mktime(0,0,0,$tmp_mon - $step,1,$tmp_year);
//得到当前月的上一个月
return $tmp_premonth;
}
/**
* 初始化参数
*
*/
function _init(){
$this->nowWeek = date('w', $this->date);
$this->nowMonth = date('m', $this->date);
$this->nextMonth = date('m', $this->date + 86400 * $this->count);
$this->startDate = $this->date - 86400 * $this->nowWeek;//获取开始日期
}
/**
* 获取html
*
*/
function getHtml(){
$box = $this->getBox();
while($this->getNextMonth($this->date, 2) lastDate){
$this->date = $this->getNextMonth($this->date);
$this->_init();
$box .= $this->getBox();
}
return
{$box}
EOF;
}
/**
* 获取日历块
*
*/
function getBox(){
$result = '
- ';
- ' . $tmp_d . '' . $nums . '' . $price . '';
- ' . $tmp_d . ' ';
$startDate = $this->startDate;
for($i = 0; $i count; $i++){
$tmp_y = date("Y-n-d", $startDate);
$tmp_m = date("m", $startDate);
$tmp_d = date("d", $startDate);
if(isset($this->prices[$startDate]) && is_array($this->prices[$startDate])){
$nowtime = date("Y-m-d",$this->prices[$startDate]['nowtime']);
$price = $this->prices[$startDate]['price'] ? '¥' . $this->prices[$startDate]['price'] : '暂无';
$nums = $this->prices[$startDate]['nums'] > 10 ? '充足' : '剩' . $this->prices[$startDate]['nums'];
} else {
$price = '';
$nums = '';
}
if($startDate >= $this->date){
$result .= '
} else {
$result .= '
}
if(($i count - 1) && (date('w', $startDate) == 6)){
$result .= '
- ';
}
$startDate += 86400;
}
$result .= "
$isShow = '';
if($this->original_date != $this->date){
$isShow = ' style="display:none"';
}
echo "
";
return
出行日价格表
{$this->getHead()}
- 星期日
- 星期一
- 星期二
- 星期三
- 星期四
- 星期五
- 星期六
{$result}
EOF;
}
/**
* 头部设置月份按钮
*
*/
function getHead(){
$result = '';
$preIcon = $this->getPreMonth($this->date) > $this->getPreMonth($this->original_date) ? "search_pp_cal_nevm_icon" : "search_pp_cal_nevm_no_icon";//开始
$nextIcon = $this->getNextMonth($this->date, 2) lastDate ? "search_pp_cal_nextm_icon" : "search_pp_cal_nextm_no_icon";//结尾
return
{$this->nowMonth}月
{$this->nextMonth}月
EOF;
}
}
$date = date("Y-m-d");
$dateTmp = strtotime($date);
$price = array();//初始化价格数据
foreach($xianluttime as $k=>$v)
{
$price[$dateTmp] = array(
'nowtime' => $v[0],
'nums' => rand(2, 12),
'price' => $v[1]
);
$dateTmp = $dateTmp + 86400;
$i++;
if($i==$countday)
{
break;
}
}
$productId = $_REQUEST['productId'];
$obj = new productDate();
$obj->create($productId, $date, $price);
echo $obj->getHtml();
?>
回复讨论(解决方案)
请贴全你的代码!(包括样式表)
你这样的片段无法测试
请贴全你的代码!(包括样式表)
你这样的片段无法测试
这是其它文件,太长不好贴,问题是在上面贴出的里,其它文件是弄的ajax产品json格式,问题是这儿:
foreach($xianluttime as $k=>$v)
{
$price[$dateTmp] = array(
'nowtime' => $v[0],
'nums' => rand(2, 12),
'price' => $v[1]
);
$dateTmp = $dateTmp + 86400;
$i++;
if($i==$countday)
{
break;
}
}
这儿设定数组里面有一个$nowtime格式是Y-m-d,设想是这个数组里面的日期才输出这里面
function getBox(){
$result = '
- ';
- ' . $tmp_d . '' . $nums . '' . $price . '';
- ' . $tmp_d . ' ';
$startDate = $this->startDate;
for($i = 0; $i count; $i++){
$tmp_y = date("Y-n-d", $startDate);
$tmp_m = date("m", $startDate);
$tmp_d = date("d", $startDate);
if(isset($this->prices[$startDate]) && is_array($this->prices[$startDate])){
$nowtime = date("Y-m-d",$this->prices[$startDate]['nowtime']);
$price = $this->prices[$startDate]['price'] ? '¥' . $this->prices[$startDate]['price'] : '暂无';
$nums = $this->prices[$startDate]['nums'] > 10 ? '充足' : '剩' . $this->prices[$startDate]['nums'];
} else {
$price = '';
$nums = '';
}
if($startDate >= $this->date){
$result .= '
} else {
$result .= '
}
if(($i count - 1) && (date('w', $startDate) == 6)){
$result .= '
- ';
}
$startDate += 86400;
}
$result .= "
如果方便可否加一下QQ
既然你只能给代码片段,那么你就应该对给出的代码做出注释
不然神知道比都在做什么
既然你只能给代码片段,那么你就应该对给出的代码做出注释
不然神知道比都在做什么
在function getBox()里面判定当$tmp_y的值是否在
foreach($xianluttime as $k=>$v)
{
$price[$dateTmp] = array(
'nowtime' => $v[0],
'nums' => rand(2, 12),
'price' => $v[1]
);
$dateTmp = $dateTmp + 86400;
$i++;
if($i==$countday)
{
break;
}
}
数组的$nowtime里面,如果存在执行这段:
不存在执行下面这段:
你把需要填写的内容数组用日期做键不就很简单了吗?
你把需要填写的内容数组用日期做键不就很简单了吗?
能具体一点吗?意思我明白了,但如何实现
for($i=1; $i这个意思能明白吗?
for($i=1; $i这个意思能明白吗?
thank you!大致方向了两个很有才,悟性太高了
我看代码一头晕
然后老徐几行代码LZ就“方向”了,佩服两个很有才,悟性太高了
我看代码一头晕
然后老徐几行代码LZ就“方向”了,佩服
谢谢项帖
下一篇: php写的发送附件的程序(一)