Hi,
Am looking through a few tutorials from the new web designer may and they have agood looking one of making a simple events calender. I've created the tables exactly, outtputted the sql to screen and ran the sql using phpmyadmin (this works btw) but can't get it working. I get an error saying:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in path
The line it highlights is:while($events[] = mysql_fetch_assoc($res))
Have tried a few things with quotes but still get nothing. Here is the original code from the mag (should display my cal with events for each day, but nothing shows even though ther are evnts in the events table):
If anyine is interested, the original files can be freely downloaded from their site. datbase.php just connects to and selects my database and header is just a bit of html code.
Thanks
Am looking through a few tutorials from the new web designer may and they have agood looking one of making a simple events calender. I've created the tables exactly, outtputted the sql to screen and ran the sql using phpmyadmin (this works btw) but can't get it working. I get an error saying:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in path
The line it highlights is:while($events[] = mysql_fetch_assoc($res))
Have tried a few things with quotes but still get nothing. Here is the original code from the mag (should display my cal with events for each day, but nothing shows even though ther are evnts in the events table):
If anyine is interested, the original files can be freely downloaded from their site. datbase.php just connects to and selects my database and header is just a bit of html code.
Thanks
PHP:
<?php
include("database.php");
include("header.php");
?>
<h1>Your Calendar</h1>
<?php
$start = strtotime("last Monday");
$finish = strtotime("next Sunday");
if(isset($_GET["offset"])) {
$offset = intval($_GET["offset"]);
$start = $start + (604800 * $offset);
$finish = $finish + (604800 * $offset);
}
$sql = "select * from events order by datetime asc";
$res = mysql_query($sql);
echo "NUM ROWS: " . mysql_num_rows($sql);
while($events[] = mysql_fetch_assoc($res)) ?>
<h2>Showing <?=date("d M Y", $start);?> - <?=date("d M Y", $finish);?></h2>
<table class="calendar"><tr>
<?php for($i = $start; $i <= $finish; $i = $i + 86400) { ?>
<td><div class="heading"><?=date("D d M Y", $i);?></div>
<div class="events">
<?php foreach($events as $key => $event) {
if(($event["datetime"] > $i) && ($event["datetime"] < ($i + 86400))) {
?><a href="edit.php?id=<?=$event["id"];?>"><?=$event["name"];?></a><br /><?php
}//End If
}//End For ?>
</div></td>
<?php
if(date("D", $i) == "Sun") {
echo '</tr><tr>';
}
}//End While
?>
</tr></table>
<br />
<table class="links">
<tr>
<td align="center">
<a href="view.php?offset=<?=$offset - 1;?>">
<img alt="Back A Week" src="images/left.png" />
<br />
Back A Week
</a>
</td>
<td align="center">
<a href="edit.php">
<img alt="New Event" src="images/new.png" />
<br />
New Event
</a>
</td>
<td align="center">
<a href="view.php">
<img alt="View Today" src="images/today.png" />
<br />
View Today
</a>
</td>
<td align="center">
<a href="view.php?offset=<?=$offset + 1;?>">
<img alt="Forward A Week" src="images/right.png" />
<br />
Forward A Week
</a>
</td>
</tr>
</table>