Jump to content

Calendar in list form (event list by month)???


steff_dk

Recommended Posts

Hi all!

I have a page where events are sorted by date like so:

2006-11-08 - Event 1
2006-11-12 - Event 2
2006-12-02 - Event 3
2006-12-05 - Event 4
2006-12-22 - Event 5
... and so on ...

The list is just the straight output from a sql clause like "select the_date, the_title from event_table order by the_date" with some <tr>'s and <td>'s in between.

I want to add a header into this list for each month so it will look like this instead:

[b]NOVEMBER 2006[/b]
2006-11-08 - Event 1
2006-11-12 - Event 2
[b]DECEMBER 2006[/b]
2006-12-02 - Event 3
2006-12-05 - Event 4
2006-12-22 - Event 5
... and so on ...

How is this done??  ???
Link to comment
Share on other sites

Yup - here's the code:

[code]<?php

//start the session
session_start();

//check to make sure the session variable is registered
if(session_is_registered('username')){

//the session variable is registered, the user is allowed to see anything that follows


//set connect attributes
$dbHost = "localhost";
$dbUser = "mydomain_dk";
$dbPass = "password";
$dbDatabase = "mydomain_dk";

//create connection
$link_id = mysql_connect($dbHost, $dbUser, $dbPass) or die (mysql_error());

//select database or catalog
mysql_select_db($dbDatabase, $link_id);

//sql statement to variable
$sql="SELECT ID, dato, titel, tilmelding FROM arrangementer WHERE dato >= CURDATE() ORDER BY dato";

//return result set to php
$result=mysql_query($sql, $link_id) or die (mysql_error());

print("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>");
print("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' >");
print("<head><meta http-equiv='content-type' content='text/html; charset=iso-8859-1' />");
print("<style type='text/css' title='currentStyle' media='screen'> @import 'css/frameinframesource.css'; </style>");
print("</head><body style='background-color: #FFFFFF'><div><h3><span>Arrangementer<br></span></h3><p class='p1'><span>");
print("<table border='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='350' id='arr_table'>");


if (!$result) echo "<TR><TD width=200><font face=arial>Henter resultat</TD>";
while (list ($ID, $dato, $titel, $tilmelding) = mysql_fetch_row ($result))
{


//hvor mange er tilmeldt
$antal=mysql_query("select * from tilmeldinger where arrangementID='$ID'", $link_id);
$rowCheck = mysql_num_rows($antal);



print("<tr><td>$dato</td><td>$titel</td><td><a href='viewarr.php?ID=$ID'><img src='grafik/tilmeld.gif' border='0'></a>&nbsp;($rowCheck)</td></tr>");
}

//close table tag and page
print("</table></span></p></div></body></html> ");

//free result set
mysql_close();

}
else{

//the session variable isn't registered, send them back to the login page
Print("FEJL! Du er ikke logget ind opdater siden og log ind.");
}

?>[/code]
Link to comment
Share on other sites

I think this should work :)

[code]<?php

//start the session
session_start();

//check to make sure the session variable is registered
if(session_is_registered('username')){

//the session variable is registered, the user is allowed to see anything that follows


//set connect attributes
$dbHost = "localhost";
$dbUser = "mydomain_dk";
$dbPass = "password";
$dbDatabase = "mydomain_dk";

//create connection
$link_id = mysql_connect($dbHost, $dbUser, $dbPass) or die (mysql_error());

//select database or catalog
mysql_select_db($dbDatabase, $link_id);

//sql statement to variable
$sql="SELECT ID, dato, titel, tilmelding FROM arrangementer WHERE dato >= CURDATE() ORDER BY dato";

//return result set to php
$result=mysql_query($sql, $link_id) or die (mysql_error());

print("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>");
print("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' >");
print("<head><meta http-equiv='content-type' content='text/html; charset=iso-8859-1' />");
print("<style type='text/css' title='currentStyle' media='screen'> @import 'css/frameinframesource.css'; </style>");
print("</head><body style='background-color: #FFFFFF'><div><h3><span>Arrangementer<br></span></h3><p class='p1'><span>");


$current=0;
$first = TRUE;
$months = array("","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
if (!$result) echo "<TR><TD width=200><font face=arial>Henter resultat</TD>";
while (list ($ID, $dato, $titel, $tilmelding) = mysql_fetch_row ($result))
{
$dates = explode("-",$dato);
if($dates['1'] != $current)
{
if(!$first) echo "</table>"; else $first = FALSE;
$current = $dates['1'];
echo "<b>".$months[$dates['1']]." ".$dates['0']"</b>";
print("<table border='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='350' id='arr_table'>");
}

//hvor mange er tilmeldt
$antal=mysql_query("select * from tilmeldinger where arrangementID='$ID'", $link_id);
$rowCheck = mysql_num_rows($antal);



print("<tr><td>$dato</td><td>$titel</td><td><a href='viewarr.php?ID=$ID'><img src='grafik/tilmeld.gif' border='0'></a>&nbsp;($rowCheck)</td></tr>");
}

//close table tag and page
print("</table></span></p></div></body></html> ");

//free result set
mysql_close();

}
else{

//the session variable isn't registered, send them back to the login page
Print("FEJL! Du er ikke logget ind opdater siden og log ind.");
}

?>[/code]

Orio.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.