Calendar price list? Calendar data box
Problem: The price quantity information cannot be displayed only when it is corresponding to the date in the array (for example, the price and number of people are displayed only when the array contains 2013-10-12 and 2013-10-21, but the program displays the price quantity information from the start date in sequence, instead of displaying it in the corresponding date in the generated calendar). If you have any experts, please give us some advice. the more you change, the more chaotic the logic.
Current 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 month
*
*/
Function createNext (){
$ This-> nextDate = $ date; // next month, to be processed
$ This-> create ($ this-> nextDate );
}
Function getNextMonth ($ tmp_date, $ step = 1 ){
// Cut year
$ Tmp_year = date ('Y', $ tmp_date );
// Cut Out Month
$ Tmp_mon = date ('M', $ tmp_date );
$ Tmp_nextmonth = mktime (0, 0, $ tmp_mon + $ step, 1, $ tmp_year );
// Obtain the next two months of the current month, starting from the next month of the latest date
Return $ tmp_nextmonth;
}
Function getPreMonth ($ tmp_date, $ step = 1 ){
// Cut year
$ Tmp_year = date ('Y', $ tmp_date );
// Cut Out Month
$ Tmp_mon = date ('M', $ tmp_date );
$ Tmp_premonth = mktime (0, 0, $ tmp_mon-$ step, 1, $ tmp_year );
// Obtain the previous month 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 the start date
}
/**
* Getting 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 <
{$ Box}
EOF;
}
/**
* Get calendar blocks
*
*/
Function getBox (){
$ 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;
}
/**
* Set the month button in the header
*
*/
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 (); // initialize 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 ['produd d'];
$ Obj = new productDate ();
$ Obj-> create ($ productId, $ date, $ price );
Echo $ obj-> getHtml ();
?>
Reply to discussion (solution)
Please paste all your code! (Including Style Sheets)
Fragments like you cannot be tested
Please paste all your code! (Including Style Sheets)
Fragments like you cannot be tested
This is another file, which is too long to be pasted. The problem is that it is pasted on it. other files are in the json format of the ajax product. The problem is:
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;
}
}
Set the $ nowtime format in the array to Y-m-d. assume that the date in the array is output.
Function getBox (){
$ Result ='
';
}
$ StartDate + = 86400;
}
$ Result. ="
";
Can I add QQ for convenience?
Since you can only give code snippets, you should comment out the given code.
Otherwise, God knows what BIDU is doing.
Since you can only give code snippets, you should comment out the given code.
Otherwise, God knows what BIDU is doing.
In function getBox (), determine whether the value of $ tmp_y is
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;
}
}
In the $ nowtime array, if the following code is executed:
'. $ Tmp_d.'. $ tmp_y. '. $ nums.'. $ price .'
';
The following section does not exist:
'. $ Tmp_d.'. $ tmp_y .'
';
Isn't it easy for you to use the date as the key for the array of content to be filled in?
Isn't it easy for you to use the date as the key for the array of content to be filled in?
Can it be more specific? I understand, but how to implement it
For ($ I = 1; $ I <31; $ I ++) {echo $ I; if (isset ($ data [$ I]) {// Output $ data [$ I] content here }}
Do you understand this?
For ($ I = 1; $ I <31; $ I ++) {echo $ I; if (isset ($ data [$ I]) {// Output $ data [$ I] content here }}
Do you understand this?
Thank you! General Direction
The two are very talented and savvy.
I think the code is dizzy.
Then let's get started with a few lines of code. LZ is "direction". I admire it.
The two are very talented and savvy.
I think the code is dizzy.
Then let's get started with a few lines of code. LZ is "direction". I admire it.
Thank you!