I'm changing my site from using mysql to mysqli. So far the changes have been quite simple but I have a calendar page with for loops which doesn't work after the switch. I'm pretty sure it's the loop which is causing the error, but I can't seem to find a fix.
Here's a selection of the code, which works with the mysql_query (which I have commented out) but doesn't with the mysqli->query
<?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>