steff_dk Posted November 7, 2006 Share Posted November 7, 2006 Hi all!I have a page where events are sorted by date like so:2006-11-08 - Event 12006-11-12 - Event 22006-12-02 - Event 32006-12-05 - Event 42006-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 12006-11-12 - Event 2[b]DECEMBER 2006[/b]2006-12-02 - Event 32006-12-05 - Event 42006-12-22 - Event 5... and so on ...How is this done?? ??? Quote Link to comment Share on other sites More sharing options...
Orio Posted November 7, 2006 Share Posted November 7, 2006 Can you post the code that outputs the table?Orio. Quote Link to comment Share on other sites More sharing options...
steff_dk Posted November 7, 2006 Author Share Posted November 7, 2006 Yup - here's the code:[code]<?php//start the sessionsession_start();//check to make sure the session variable is registeredif(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 catalogmysql_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> ($rowCheck)</td></tr>");}//close table tag and pageprint("</table></span></p></div></body></html> ");//free result setmysql_close();}else{//the session variable isn't registered, send them back to the login pagePrint("FEJL! Du er ikke logget ind opdater siden og log ind.");}?>[/code] Quote Link to comment Share on other sites More sharing options...
Orio Posted November 7, 2006 Share Posted November 7, 2006 I think this should work :)[code]<?php//start the sessionsession_start();//check to make sure the session variable is registeredif(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 catalogmysql_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> ($rowCheck)</td></tr>");}//close table tag and pageprint("</table></span></p></div></body></html> ");//free result setmysql_close();}else{//the session variable isn't registered, send them back to the login pagePrint("FEJL! Du er ikke logget ind opdater siden og log ind.");}?>[/code]Orio. Quote Link to comment Share on other sites More sharing options...
steff_dk Posted November 7, 2006 Author Share Posted November 7, 2006 I get an error here:[code]echo "<b>".$months[$dates['1']]." ".$dates['0']"</b>";[/code]Tried this without luck:[code]echo "<b> $months[$dates['1']] $dates['0']</b>";[/code]Can't figure out why, though ??? Quote Link to comment Share on other sites More sharing options...
Orio Posted November 7, 2006 Share Posted November 7, 2006 I forgot a little dot :)Change this-[code]echo "<b>".$months[$dates['1']]." ".$dates['0']"</b>";[/code]To-[code]echo "<b>".$months[$dates['1']]." ".$dates['0']."</b>";[/code]Orio. Quote Link to comment Share on other sites More sharing options...
steff_dk Posted November 7, 2006 Author Share Posted November 7, 2006 Beautiful! :DIt works flawlessly!Thanks mateEdit: to cope with months with an initial zero, e.g. "04" -> "4"[code]echo "<b>".$months[intval($dates['1'])]." ".$dates['0']."</b>";[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.