Hello,
In a weblog php automatically creates folders containing the messages of that month. Messages are stored in a mysql database and have a date field of type DATETIME.
But when i open the page i first have to click the folder (for let's say "June") to get the messages of that month.
What i want is that when the page opens php automatically loads the messages of the current month.
I know it has something to do with the cases because when i delete that particular piece of code it automatically shows all the messages.
Perhaps it's very simple but I am new to php and would be glad if someone could show me how to get this working.
Thanx in advance
Undersound
<?
$sql = "SELECT DISTINCT(MONTH(datum)) as maand FROM weblog ORDER BY datum DESC LIMIT 1";
$result = @mysql_query($sql);
$CurrentMonth = @mysql_fetch_array($result);
if (is_numeric($m)) {
if (($m < 1) || ($m > 12)) {
$m = $CurrentMonth[0];
}
} else {
$m = $CurrentMonth[0];
}
include ("algemeen.php");
$link = dbConnect();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<link rel="stylesheet" type="text/css" href="../css/content.css">
</head>
<body leftmargin="0" topmargin="0">
<table width="100%" height="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="133" rowspan="2" height="100%" valign="top">
<table width="133" height="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="133" height="10" valign="top" colspan="2" style="border-right: 1px solid #242E42; border-bottom: 2px dotted #242E42; background-image: url('../img/1x1.gif'); background-repeat: repeat; background-position: top;" class="left1" align="center">
<b>:::: weblog ::::</b>
</td>
</tr>
<tr>
<td width="133" height="10" valign="top" colspan="2" style="border-right: 1px solid #242E42;" class="left2" align="left">
<br>
<div id='navigation'>
Archief:
</div>
</td>
</tr>
<tr>
<td width="10" class="left3">
</td>
<td width="133" height="*" valign="top" style="border-right: 1px solid #242E42;" class="left2" align="left">
<table width="100%">
<br>
<br>
<?php
$sql = "SELECT DISTINCT(MONTH(datum)) as maand FROM weblog ORDER BY datum DESC";
$result = @mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
switch($row[0]) {
case 1:
echo "<tr><td width=\"10\" class=\"left2\" align=\"left\"><img src='../img/icon_folder.gif'></img></td><td width=\"123\" align=\"left\"><a href=\"".$PHP_SELF."?m=".$row[0]."\" target=\"_self\"> januari</a></td></tr>";
break;
case 2:
echo "<tr><td width=\"10\" class=\"left2\" align=\"left\"><img src='../img/icon_folder.gif'></img></td><td width=\"123\" align=\"left\"><a href=\"".$PHP_SELF."?m=".$row[0]."\" target=\"_self\"> februari</a></td></tr>";
break;
case 3:
echo "<tr><td width=\"10\" class=\"left2\" align=\"left\"><img src='../img/icon_folder.gif'></img></td><td width=\"123\" align=\"left\"><a href=\"".$PHP_SELF."?m=".$row[0]."\" target=\"_self\"> maart</a></td></tr>";
break;
case 4:
echo "<tr><td width=\"10\" class=\"left2\" align=\"left\"><img src='../img/icon_folder.gif'></img></td><td width=\"123\" align=\"left\"><a href=\"".$PHP_SELF."?m=".$row[0]."\" target=\"_self\"> april</a></td></tr>";
break;
case 5:
echo "<tr><td width=\"10\" class=\"left2\" align=\"left\"><img src='../img/icon_folder.gif'></img></td><td width=\"123\" align=\"left\"><a href=\"".$PHP_SELF."?m=".$row[0]."\" target=\"_self\"> mei</a></td></tr>";
break;
case 6:
echo "<tr><td width=\"10\" class=\"left2\" align=\"left\"><img src='../img/icon_folder.gif'></img></td><td width=\"123\" align=\"left\"><a href=\"".$PHP_SELF."?m=".$row[0]."\" target=\"_self\"> juni</a></td></tr>";
break;
case 7:
echo "<tr><td width=\"10\" class=\"left2\" align=\"left\"><img src='../img/icon_folder.gif'></img></td><td width=\"123\" align=\"left\"><a href=\"".$PHP_SELF."?m=".$row[0]."\" target=\"_self\"> juli</a></td></tr>";
break;
case 8:
echo "<tr><td width=\"10\" class=\"left2\" align=\"left\"><img src='../img/icon_folder.gif'></img></td><td width=\"123\" align=\"left\"><a href=\"".$PHP_SELF."?m=".$row[0]."\" target=\"_self\"> augustus</a></td></tr>";
break;
case 9:
echo "<tr><td width=\"10\" class=\"left2\" align=\"left\"><img src='../img/icon_folder.gif'></img></td><td width=\"123\" align=\"left\"><a href=\"".$PHP_SELF."?m=".$row[0]."\" target=\"_self\"> september</a></td></tr>";
break;
case 10:
echo "<tr><td width=\"10\" class=\"left2\" align=\"left\"><img src='../img/icon_folder.gif'></img></td><td width=\"123\" align=\"left\"><a href=\"".$PHP_SELF."?m=".$row[0]."\" target=\"_self\"> oktober</a></td></tr>";
break;
case 11:
echo "<tr><td width=\"10\" class=\"left2\" align=\"left\"><img src='../img/icon_folder.gif'></img></td><td width=\"123\" align=\"left\"><a href=\"".$PHP_SELF."?m=".$row[0]."\" target=\"_self\"> november</a></td></tr>";
break;
case 12:
echo "<tr><td width=\"10\" class=\"left2\" align=\"left\"><img src='../img/icon_folder.gif'></img></td><td width=\"123\" align=\"left\"><a href=\"".$PHP_SELF."?m=".$row[0]."\" target=\"_self\"> december</a></td></tr>";
break;
}
}
?>
</table>
</td>
</tr>
</table>
</td>
<td width="100%" class="right" valign="top" align="center">
<table width="100%>
<tr height="65"><td height="40"> </td></tr>
<tr><td width="5%" align="center"> </td><td align="left">
<?php
$sql = "SELECT * from weblog";
$result = @mysql_query($sql);
$aantal = @mysql_num_rows($result);
$sql = "SELECT link, melding, foto, datum FROM weblog WHERE Month(datum) = " . $m . " ORDER BY datum DESC";
$result = @mysql_query($sql);
if ($result && @mysql_num_rows($result) > 0)
{
$meldingen = "";
while ($regel=mysql_fetch_array($result)) {
$naam = htmlspecialchars ($regel["naam"]);
$link = htmlspecialchars ($regel["link"]);
$foto = htmlspecialchars ($regel["foto"]);
$datum = substr($regel['datum'],0,16);
$boodschap = $regel["melding"];
$boodschap = eregi_replace("\r\n\r\n","\r\n",$boodschap);
$boodschap = eregi_replace("\r","",$boodschap);
$boodschap = nl2br($boodschap);
$boodschap = wordwrap($boodschap, 78, "\n", 1);
$meldingen .= "<table border='0' style='border: 1px solid #242E42;'><tr><td align='left'><b>datum: $datum</b></table><br>";
$meldingen .= "<table border='0' width='550' style='border: 1px solid #242E42;'><tr><td>$boodschap<br><br><a href='Http://$link' target='_blank'>$link</a></td></tr><tr><td>$foto</td></tr></table><br><br><br>";
}
echo "$meldingen";
}
?>
</td>
</tr>
</table>
</body>
</html>
[code=php]