新手求助现在一家CMS网站实习,之前并未接触过php mysql故学习中
<!-- 开盘日历 -->
<script type="text/javascript" src="{$tplurl}js/js_imch0702.js"></script>
<div class="coltit mb10">
<h3 class="tit">开盘日历</h3>
</div>
<?php
//开盘日历函数140701
function calendar_monthes(){
//$timestamp = TIMESTAMP;
//$db = _08_factory::getDBO();
//当前年份,如果当前月份是1~6月,那么就要显示上一年下半年的数据。如果当前月份是7~12月之间,则年份要下一年的上半年数据
$cur_year = date('Y');
$pre_year = $cur_year - 1;
$nex_year = $cur_year + 1;
$cur_month = date('m');
$date_arr = array();
if($cur_month < 7){
$date_arr = array(
$pre_year."_1"=>array(7,8,9,10,11,12),
$cur_year."_1"=>array(1,2,3,4,5,6),
$cur_year."_2"=>array(7,8,9,10,11,12)
);
}else{
$date_arr = array(
$cur_year."_1"=>array(1,2,3,4,5,6),
$cur_year."_2"=>array(7,8,9,10,11,12),
$nex_year."_1"=>array(1,2,3,4,5,6)
);
}
return $date_arr;
}
//开盘内容
function calendar_content(){
include_once M_ROOT.'./include/mysql.cls.php';
$dbcharset = !$dbcharset && in_array(strtolower($mcharset),array('gbk','big5','utf-8')) ? str_replace('-', '', $mcharset) : $dbcharset;
$db = new cls_mysql;
$dbhost = ''; //为保密数据库连接信息已删除
$dbuser = '';
$dbpw = '';
$dbname = '';
$pconnect = 0;
$db->connect($dbhost,$dbuser,$dbpw,$dbname,$pconnect,true,$dbcharset);
//当前年份,如果当前月份是1~6月,那么就要显示上一年下半年的数据。如果当前月份是7~12月之间,则年份要下一年的上半年数据
$cur_year = date('Y');
$cur_month = date('m');
if($cur_month < 7){
$time_0 = strtotime(($cur_year - 1)."-7");
$time_1 = strtotime(($cur_year + 1)."-1");
}else{
$time_0 = strtotime(($cur_year)."-1");
$time_1 = strtotime(($cur_year + 1)."-7");
}
$data = array();
$sql = "SELECT a.,c.kprq,c.kpsj, FROM cms_archives15 as a INNER JOIN cms_archives_4 as c ON a.aid = c.aid WHERE a.ccid8 like '%200%' AND c.kpsj>= $time_0 AND c.kpsj < $time_1 ORDER BY c.kpsj ASC ";
$query = $db->query($sql);
while($row = $db->fetch_array($query)){
$_url = $row['nowurl'];
$_url = substr($_url, 0, -21);
$_url .= "view.html";
$_year = date('Y',$row['kpsj']);
$_month = date('n',$row['kpsj']);
$_day = date('j',$row['kpsj']);
$_m_and_d = date("m月d日",$row['kpsj']);
$content = array('url'=>$_url,'title'=>"[".$coclasses1[$row['ccid1']]['title']."]".$row['subject']);
$data[]=array(
//'plh_ts' => $row['plh_ts'],
'kprq' => $row['kprq'],
'url' => $_url,
'ccid1' => $row['ccid1'],
'subject' => $row['subject'],
'dj' => $row['dj'],
'y' => $_year,
'm' => $_month,
'd' => $_day
);
}
return $data;
}
$date_arr = calendar_monthes();
// print_r($date_arr);
?>
<div class="colC_iner1 pb8">
<div id="calendarBox" class="calendarBox">
<div class="nav_kprl">
<h2 id="yearTitle"><?php $_keys_arr = array_keys($date_arr); echo substr($keys_arr[0],0,4);?></h2>
<span id="leftBtn" class="btn_kprl leftBtn">左</span>
<div class="calendarTab" id="calendarTab">
<div id="inner" style="margin-left:-180px;">
<div class="t_width">
<?php
$i = 1;
foreach($date_arr as $key => $val){
if($i == 1) echo "<ul id="currentUl_one" year="".substr($key,0,4)."">";
else echo "<ul id="currentUl".($i==2?"two":"three")."" year="".substr($key,0,4)."">";
foreach($val as $k => $v ){
echo "<li ".($i==1 ? "class="calendarOn"":'').">".$v."月</li>";
}
$i ++;
echo "</ul>";
}
unset($i);
?>
</div>
</div>
</div>
<span id="rightBtn" class="btn_kprl rightBtn">右</span>
<div class="blank0"></div>
</div>
<div id="calendarCon" class="con_kprl">
<div id="innerCon" class="iner_kprl" style="margin-left:-280px">
<?php
$calendar_content = calendar_content();
$i = 1;
foreach($date_arr as $k => $v){
$_year = substr($k,0,4);
echo "<div id="content".$i."" class="kp-content".$i."">
<div id="scrollBox_all".$i."" class="scrollBox_all".$i."">
<div id="scrollBox".($i==2?"C$i":$i)."" class="scrollBoxC".$i."">
<div class="scrollContent">";
$i ++;
foreach($v as $mon){
$date_str = '';
echo "<ul mon="".$mon."月">";
foreach($calendar_content as $key => $val){
if($val['y'] == $_year && $val['m'] == $mon){
if($date_str != $val['d']){
$date_str = $val['d'];
echo "<li class="ico"><span>".$mon."月".$val['d']."日</span></li>";
}
echo "<li>
<div class="ell w200">
[$val[ccid1]]
<a target="_blank"
</div>
</li>";
}
}
echo "</ul>";
}
echo " </div>
</div>
</div>
</div>";
}
unset($i);
?>
</div>
</div>
<div id="calendarMonth"><?php echo date("n")?>月</div>
</div>
</div>
<script type="text/javascript" src="{$tplurl}js/kaipan.js"></script>
<!-- /开盘日历 -->
由于某些原因无法查看日志,不得已用很笨的排除法
发现是$calendar_content = calendar_content();造成的错误
即在红字标注的php内问题,不知是定义问题还是数据库查询问题?求各位指点迷津
附:sql语句
SELECT a.,c.kprq,c.kpsj FROM cms_archives15 as a INNER JOIN cms_archives_4 as c ON a.aid = c.aid WHERE c.kpsj AND c.kpsj ORDER BY c.kpsj ASC
可查询到想要的结果
$sql="SELECTa.*,c.kprq,c.kpsj,FROMcms_archives15asa INNERJOINcms_archives_4ascONa.aid=c.aidWHEREa.ccid8like'%200%'ANDc.kpsj>=$time_0 ANDc.kpsj<$time_1ORDERBYc.kpsjASC";
var_dump($sql); //这里不会为Null
$query=$db->query($sql);
var_dump($sql); //如果是里为Null,看下cls_mysql::query()的底层实现,如果可以,改用mysql_query来实现
while($row=$db->fetch_array($query)){奇怪了都没输出底层代码看不到 $query=$db->query($sql);while($row=$db->fetch_array($query)){
可以精确定位问题,如在上面这两行代码之前将结果输出一下。看下没有内容输出具体发生在哪里。
var_dump($sql);为null这是?版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。