我将我的网站从使用mysql改为mysqli。到目前为止,变化非常简单,但我有一个带有for循环的日历页面,在切换后不起作用。我很确定它是导致错误的循环,但我似乎无法找到解决办法。
这里有一些代码选择,它与mysql_query一起使用(我已经注释掉了)但没有使用mysqli->查询
<?php include("conn.php");
$today = mktime(12,0,0,date("m"),1,date("Y"));
$currentmonth = date(m, $today);
$currentyear = date(Y, $today);
$prevmonth = $currentmonth - 1;
$prevyear = $currentyear;
$prevdate = mktime(12, 0, 0, $prevmonth, 1, $prevyear);
$pdim = date("t", $prevdate);
function showMonth($month, $year, $pdims, $prevmonths, $prevyears)
{
$caldate = mktime(12, 0, 0, $month, 1, $year);
$offset = date("w", $caldate);
$pdimsplus = $pdims + 1;
$enddays = $pdimsplus - $offset;
for($i = 1; $i <= $offset; $i++)
{
$qryhead1 = "SELECT * FROM photos WHERE day(date) = $enddays AND month(date) = $prevmonths AND year(date) = $prevyears LIMIT 1";
//$res1 = $mysqli->query($qryhead1);
//$noofrec1 = $res1->num_rows;
//if ($noofrec1 > 0) {
//while ($row1 = mysqli_fetch_object($res1)) {
$res1 = mysql_query($qryhead1);
$noofrec1 = mysql_num_rows($res1);
if ($noofrec1 > 0) {
while ($row1 = mysql_fetch_object ($res1)) {
$id = $row1->id;
$image = $row1->image; ?>
<div><?php print("$enddays"); ?><a href="<?php print("$id"); ?>"><img src="/images/<?php print("$image"); ?>"></a></div>
<?php }
} else { ?>
<div><?php print("$enddays"); ?></div>
<?php }
$enddays++;
}
}
?>
<div>
<?php showMonth($currentmonth, $currentyear, $pdim, $prevmonth, $prevyear); ?>
</div>
答案 0 :(得分:0)
如果您有一个$mysqli
对象(我假设您在conn.php中创建了一个),那么您不会将其作为自定义函数showMonth()
的函数参数传递。请阅读variable scope。