1.单个操作:
代码
$dateYear=date('Y');//当前年份
$dateMonth = date('m');//当前月份
//exit($dateMonth);
//判断当前年月份是否有记录
$sql="SELECT * FROM ".tname('creditlog_byMonth')." WHERE uid='".$uid."' and year(FROM_UNIXTIME(dateline))='".$dateYear."' and month(FROM_UNIXTIME(dateline))='".$dateMonth."'";
//exit ($sql);
$query = $_SGLOBAL['db']->query($sql);
$creditlog_byMonth = $_SGLOBAL['db']->fetch_array($query);
$curDetailID=0;//当前详细记录ID(以方便修改操作)
//判断是否有记录...
if(empty($creditlog_byMonth))
{
//添加:
$sql="insert into ".tname('creditlog_byMonth')."(uid,credit,dateline) values ('".$uid."','".$rule['credit']."','".$_SGLOBAL[timestamp]."')";
//exit($sql);
$_SGLOBAL['db']->query($sql) ;
}
else {//修改:
$curDetailID=$creditlog_byMonth[id];
$sql="update ".tname('creditlog_byMonth')." set credit=credit+".$rule['credit']." where id=".$curDetailID;
$_SGLOBAL['db']->query($sql) ;
}
$dateMonth = date('m');//当前月份
//exit($dateMonth);
//判断当前年月份是否有记录
$sql="SELECT * FROM ".tname('creditlog_byMonth')." WHERE uid='".$uid."' and year(FROM_UNIXTIME(dateline))='".$dateYear."' and month(FROM_UNIXTIME(dateline))='".$dateMonth."'";
//exit ($sql);
$query = $_SGLOBAL['db']->query($sql);
$creditlog_byMonth = $_SGLOBAL['db']->fetch_array($query);
$curDetailID=0;//当前详细记录ID(以方便修改操作)
//判断是否有记录...
if(empty($creditlog_byMonth))
{
//添加:
$sql="insert into ".tname('creditlog_byMonth')."(uid,credit,dateline) values ('".$uid."','".$rule['credit']."','".$_SGLOBAL[timestamp]."')";
//exit($sql);
$_SGLOBAL['db']->query($sql) ;
}
else {//修改:
$curDetailID=$creditlog_byMonth[id];
$sql="update ".tname('creditlog_byMonth')." set credit=credit+".$rule['credit']." where id=".$curDetailID;
$_SGLOBAL['db']->query($sql) ;
}
代码
$dateYear=date('Y');//当前年份
$dateMonth = date('m');//当前月份
//exit($dateMonth);
//判断当前年月份是否有记录
$sql="SELECT * FROM ".tname('creditlog_byMonth')." WHERE uid='".$uid."' and year(FROM_UNIXTIME(dateline))='".$dateYear."' and month(FROM_UNIXTIME(dateline))='".$dateMonth."'";
//exit ($sql);
$query = $_SGLOBAL['db']->query($sql);
$creditlog_byMonth = $_SGLOBAL['db']->fetch_array($query);
$curDetailID=0;//当前详细记录ID(以方便修改操作)
//判断是否有记录...
if(empty($creditlog_byMonth))
{
//添加:
$sql="insert into ".tname('creditlog_byMonth')."(uid,credit,dateline) values ('".$uid."','".$rule['credit']."','".$_SGLOBAL[timestamp]."')";
//exit($sql);
$_SGLOBAL['db']->query($sql) ;
}
else {//修改:
$curDetailID=$creditlog_byMonth[id];
$sql="update ".tname('creditlog_byMonth')." set credit=credit+".$rule['credit']." where id=".$curDetailID;
$_SGLOBAL['db']->query($sql) ;
}
$dateMonth = date('m');//当前月份
//exit($dateMonth);
//判断当前年月份是否有记录
$sql="SELECT * FROM ".tname('creditlog_byMonth')." WHERE uid='".$uid."' and year(FROM_UNIXTIME(dateline))='".$dateYear."' and month(FROM_UNIXTIME(dateline))='".$dateMonth."'";
//exit ($sql);
$query = $_SGLOBAL['db']->query($sql);
$creditlog_byMonth = $_SGLOBAL['db']->fetch_array($query);
$curDetailID=0;//当前详细记录ID(以方便修改操作)
//判断是否有记录...
if(empty($creditlog_byMonth))
{
//添加:
$sql="insert into ".tname('creditlog_byMonth')."(uid,credit,dateline) values ('".$uid."','".$rule['credit']."','".$_SGLOBAL[timestamp]."')";
//exit($sql);
$_SGLOBAL['db']->query($sql) ;
}
else {//修改:
$curDetailID=$creditlog_byMonth[id];
$sql="update ".tname('creditlog_byMonth')." set credit=credit+".$rule['credit']." where id=".$curDetailID;
$_SGLOBAL['db']->query($sql) ;
}
2.循环操作:
代码
$sql="SELECT * FROM ".tname('creditlog_byMonth')." WHERE year(FROM_UNIXTIME(dateline))='".$dateYear."' and month(FROM_UNIXTIME(dateline))='".$dateMonth."' order by dateline desc limit 0,9";
//exit ($sql);
$query = $_SGLOBAL['db']->query($sql);
$tmpArr=array();
while ($tmpArr = $_SGLOBAL['db']->fetch_array($query)) {
$out.=$tmpArr['credit']."<br/>";
}
exit($out);
//exit ($sql);
$query = $_SGLOBAL['db']->query($sql);
$tmpArr=array();
while ($tmpArr = $_SGLOBAL['db']->fetch_array($query)) {
$out.=$tmpArr['credit']."<br/>";
}
exit($out);
上面是自己对其简单用法,其实它还有高级用法,,,
1 $dateYear=date('Y');//当前年份
2 $dateMonth = date('m');//当前月份
3 //exit($dateMonth);
4 //判断当前年月份是否有记录
5 $sql="SELECT * FROM ".tname('creditlog_byMonth')." WHERE uid='".$uid."' and year(FROM_UNIXTIME(dateline))='".$dateYear."' and month(FROM_UNIXTIME(dateline))='".$dateMonth."'";
6 //exit ($sql);
7 $query = $_SGLOBAL['db']->query($sql);
8 $creditlog_byMonth = $_SGLOBAL['db']->fetch_array($query);
9 $curDetailID=0;//当前详细记录ID(以方便修改操作)
10 //判断是否有记录...
11 if(empty($creditlog_byMonth))
12 {
13 //添加:
14 $sql="insert into ".tname('creditlog_byMonth')."(uid,credit,dateline) values ('".$uid."','".$rule['credit']."','".$_SGLOBAL[timestamp]."')";
15 //exit($sql);
16 $_SGLOBAL['db']->query($sql) ;
17
18 }
19 else {//修改:
20 $curDetailID=$creditlog_byMonth[id];
21 $sql="update ".tname('creditlog_byMonth')." set credit=credit+".$rule['credit']." where id=".$curDetailID;
22 $_SGLOBAL['db']->query($sql) ;
23
24 }
2 $dateMonth = date('m');//当前月份
3 //exit($dateMonth);
4 //判断当前年月份是否有记录
5 $sql="SELECT * FROM ".tname('creditlog_byMonth')." WHERE uid='".$uid."' and year(FROM_UNIXTIME(dateline))='".$dateYear."' and month(FROM_UNIXTIME(dateline))='".$dateMonth."'";
6 //exit ($sql);
7 $query = $_SGLOBAL['db']->query($sql);
8 $creditlog_byMonth = $_SGLOBAL['db']->fetch_array($query);
9 $curDetailID=0;//当前详细记录ID(以方便修改操作)
10 //判断是否有记录...
11 if(empty($creditlog_byMonth))
12 {
13 //添加:
14 $sql="insert into ".tname('creditlog_byMonth')."(uid,credit,dateline) values ('".$uid."','".$rule['credit']."','".$_SGLOBAL[timestamp]."')";
15 //exit($sql);
16 $_SGLOBAL['db']->query($sql) ;
17
18 }
19 else {//修改:
20 $curDetailID=$creditlog_byMonth[id];
21 $sql="update ".tname('creditlog_byMonth')." set credit=credit+".$rule['credit']." where id=".$curDetailID;
22 $_SGLOBAL['db']->query($sql) ;
23
24 }