日历价格表?
问题:价格人数信息不能对应数组里面有的日期才显示(比如数组里面有2013-10-12和2013-10-21才有价格和人数,但程序会依次从开始日期显示,而不是在生成的日历里面对应的日期里才显示),有高手请指点一下,越改逻辑越混乱了。
现在效果如图:
代码如下:
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 = '
- ';
$startDate = $this->startDate;
for($i = 0; $i count; $i++){

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
