Calendar Price list?

Source: Internet
Author: User
Calendar Data Box

Problem: The price number information can not correspond to the array of the date to display (such as the array has 2013-10-12 and 2013-10-21 only price and number, but the program will be displayed in turn from the start date, not in the generated calendar within the corresponding date), there are experts please point out, The more you change the logic, the more confusing.
Now the effect
The code is as follows:

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);
}
/**
* Next one months
*
*/
function Createnext () {
$this->nextdate = $date; Next month, awaiting treatment
$this->create ($this->nextdate);
}

function Getnextmonth ($tmp _date, $step = 1) {
Cut out year
$tmp _year= Date (' Y ', $tmp _date);
Cut out Month
$tmp _mon =date (' m ', $tmp _date);
$tmp _nextmonth=mktime (0,0,0, $tmp _mon + $step, 1, $tmp _year);
Get the start of the next month for the next 2 months of the current month, the latest date
return $tmp _nextmonth;
}

function Getpremonth ($tmp _date, $step = 1) {
Cut out year
$tmp _year= Date (' Y ', $tmp _date);
Cut out Month
$tmp _mon =date (' m ', $tmp _date);
$tmp _premonth=mktime (0,0,0, $tmp _mon-$step, 1, $tmp _year);
Get the last one months of the current month
return $tmp _premonth;
}
/**
* Initialization Parameters
*
*/
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;//get start date
}
/**
* Get HTML
*
*/
function gethtml () {
$box = $this->getbox ();
while ($this->getnextmonth ($this->date, 2) < $this->lastdate) {
$this->date = $this->getnextmonth ($this->date);
$this->_init ();
$box. = $this->getbox ();
}

Return <<
PRODUCT_ID} ">
{$box}

EOF;
}
/**
* Get Calendar blocks
*
*/
function Getbox () {
$result = '
    ';
    $startDate = $this->startdate;

    for ($i = 0; $i < $this->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 ']: ' No ';
    $nums = $this->prices[$startDate] [' nums '] > 10? ' Ample ': ' Left '. $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 < $this->count-1) && (Date (' W ', $startDate) = = 6)) {
    $result. = '
      ';
      }
      $startDate + = 86400;
      }
      $result. = "
";

$isShow = ";
if ($this->original_date! = $this->date) {
$isShow = ' style= ' Display:none ';
}
echo "
";
Return <<

Travel Day Price List



{$this->gethead ()}



    • Sunday

    • Monday

    • Tuesday

    • Wednesday

    • Thursday

    • Friday

    • Saturday


{$result}

EOF;
}
/**
* Head Set Month button
*
*/
function GetHead () {
$result = ";
$preIcon = $this->getpremonth ($this->date) > $this->getpremonth ($this->original_date)? "Search_pp_cal_nevm_icon": "Search_pp_cal_nevm_no_icon";//Start
$nextIcon = $this->getnextmonth ($this->date, 2) < $this->lastdate? "Search_pp_cal_nextm_icon": "Search_pp_cal_nextm_no_icon";//End
Return <<


{$this->nowmonth} month


{$this->nextmonth} month


EOF;
}

}



$date = Date ("y-m-d");
$DATETMP = Strtotime ($date);
$price = Array ();//initialization of price data
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 ();
?>


Reply to discussion (solution)

Please paste all your code! (including style sheets)
You can't test a fragment like this.

Please paste all your code! (including style sheets)
You can't test a fragment like this.
This is the other file, too long not paste, the problem is posted above, the other file is to get the AJAX product JSON format, the problem is here:
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
}
}
Here the array has a $nowtime format is y-m-d, it is assumed that the date in this array to output this inside
function Getbox () {
$result = '

    ';
    $startDate = $this->startdate;

    for ($i = 0; $i < $this->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 ']: ' No ';
    $nums = $this->prices[$startDate] [' nums '] > 10? ' Ample ': ' Left '. $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 < $this->count-1) && (Date (' W ', $startDate) = = 6)) {
    $result. = '
      ';
      }
      $startDate + = 86400;
      }
      $result. = "
";
If convenient can add QQ

Since you can only give code snippets, you should comment on the code given
Or God knows what's better than what he's doing.

Since you can only give code snippets, you should comment on the code given
Or God knows what's better than what he's doing.
In function Getbox () determine if the value of $tmp_y is in the
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
}
}
Array of $nowtime inside, if there is execution of this paragraph:

  • '. $tmp _d. ". $tmp _y. ". $nums. ". $price. '
  • ';

    Does not exist perform the following paragraph:
  • '. $tmp _d. ". $tmp _y. '
  • ';

    Do you want to fill in the contents of the array with the date of the key is not very simple?

    Do you want to fill in the contents of the array with the date of the key is not very simple?
    Can you make it a little more specific? Meaning I understand, but how to achieve

    for ($i =1; $i <31; $i + +) {  echo $i;  if (Isset ($data [$i]) {    //output here $data [$i]}  }
    Does that mean you understand?

    for ($i =1; $i <31; $i + +) {  echo $i;  if (Isset ($data [$i]) {    //output here $data [$i]}  }
    Does that mean you understand?
    Thank you! General direction.

    Two are very talented, the perception is too high
    I look at the code a dizzy

    Then Lao Xu a few lines of code LZ on the "direction", admire

    Two are very talented, the perception is too high
    I look at the code a dizzy

    Then Lao Xu a few lines of code LZ on the "direction", admire
    Thank you for the Post

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.