日历 数据 box
问题:价格人数信息不能对应数组里面有的日期才显示(比如数组里面有2013-10-12和2013-10-21才有价格和人数,但程序会依次从开始日期显示,而不是在生成的日历里面对应的日期里才显示),有高手请指点一下,越改逻辑越混乱了。
现在效果如图:
代码如下:
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 product_id}>
{$box}
eof;
}
/**
* 获取日历块
*
*/
function getbox(){
$result = '';
$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 .= '' . $tmp_d . '' . $tmp_y . '' . $nums . '' . $price . '
';
} else {
$result .= '' . $tmp_d . '' . $tmp_y . '
';
}
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 = '
';
$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 .= '' . $tmp_d . '' . $tmp_y . '' . $nums . '' . $price . '
';
} else {
$result .= '' . $tmp_d . '' . $tmp_y . '
';
}
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里面,如果存在执行这段:
' . $tmp_d . '' . $tmp_y . '' . $nums . '' . $price . '
';
不存在执行下面这段:
' . $tmp_d . '' . $tmp_y . '
'; 你把需要填写的内容数组用日期做键不就很简单了吗?
你把需要填写的内容数组用日期做键不就很简单了吗?
能具体一点吗?意思我明白了,但如何实现
for($i=1; $i<31; $i++) { echo $i; if(isset($data[$i])) { //这里输出 $data[$i] 的内容 }}
这个意思能明白吗?
for($i=1; $i<31; $i++) { echo $i; if(isset($data[$i])) { //这里输出 $data[$i] 的内容 }}
这个意思能明白吗?
thank you!大致方向了
两个很有才,悟性太高了
我看代码一头晕
然后老徐几行代码lz就“方向”了,佩服
两个很有才,悟性太高了
我看代码一头晕
然后老徐几行代码lz就“方向”了,佩服
谢谢项帖