Archiefscript
Frederic - 22/02/2006 18:49 (laatste wijziging 22/02/2006 19:35)
PHP ver gevorderde
Ik gebruik volgende code als archiefscript:
<?php
$maanden = array("Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December");
$sql_jaar = mysql_query("SELECT DISTINCT(DATE_FORMAT(datum, '%Y')) AS jaar FROM blog ORDER BY jaar DESC") ;
while ($rij_jaar = mysql_fetch_array($sql_jaar)) {
echo "<h2>" . $rij_jaar['jaar'] . "</h2>" ;
$sql_maand = mysql_query("SELECT DISTINCT(DATE_FORMAT(datum, '%m')) AS maand FROM blog WHERE DATE_FORMAT(datum, '%Y') = '" . $rij_jaar['jaar'] . "' ORDER BY maand DESC") ;
while ($rij_maand = mysql_fetch_array($sql_maand)) {
echo "<span style=\"font-weight: bold; margin-left: 15px;\">• " . $maanden[$rij_maand['maand']-1]. "</span><br />" ;
$sql_dag = mysql_query("SELECT id, onderwerp, DATE_FORMAT(datum, '%d') AS dag FROM blog WHERE DATE_FORMAT(datum, '%m') = '" . $rij_maand['maand'] . "' ORDER BY dag DESC") ;
while ($rij_dag = mysql_fetch_array($sql_dag)) {
echo "<span style=\"margin-left: 30px;\">• " . $rij_dag['dag']. ": " . $rij_dag['onderwerp'] . "</span><br />" ;
}
}
}
?>
<?php
$maanden = array ( "Januari" , "Februari" , "Maart" , "April" , "Mei" , "Juni" , "Juli" , "Augustus" , "September" , "Oktober" , "November" , "December" ) ;
$sql_jaar = mysql_query ( "SELECT DISTINCT(DATE_FORMAT(datum, '%Y')) AS jaar FROM blog ORDER BY jaar DESC" ) ; echo "<h2>" . $rij_jaar [ 'jaar' ] . "</h2>" ;
$sql_maand = mysql_query ( "SELECT DISTINCT(DATE_FORMAT(datum, '%m')) AS maand FROM blog WHERE DATE_FORMAT(datum, '%Y') = '" . $rij_jaar [ 'jaar' ] . "' ORDER BY maand DESC" ) ; echo "<span style=\" font-weight: bold; margin-left: 15px;\" >• " . $maanden [ $rij_maand [ 'maand' ] - 1 ] . "</span><br />" ;
$sql_dag = mysql_query ( "SELECT id, onderwerp, DATE_FORMAT(datum, '%d ') AS dag FROM blog WHERE DATE_FORMAT(datum, '%m') = '" . $rij_maand [ 'maand' ] . "' ORDER BY dag DESC" ) ; echo "<span style=\" margin-left: 30px;\" >• " . $rij_dag [ 'dag' ] . ": " . $rij_dag [ 'onderwerp' ] . "</span><br />" ; }
}
}
?>
Maar om dat uit te rekenen heeft de MySQL server precies moeilijkheden (traag)... Zitten er fouten in dit scriptje/kan het korter volgens iemand?
1 antwoord
Gesponsorde links
haytjes - 22/02/2006 21:13 (laatste wijziging 22/02/2006 21:13)
JS gevorderde
misschien 1 while'tje met sql gebruiken???
<?php
$maanden = array("Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December");
$jaar = "";
$maand = "";
$sql_jaar = mysql_query("
SELECT DATE_FORMAT(datum, '%Y') AS jaar,
DATE_FORMAT(datum, '%m') AS maand,
id, onderwerp, DATE_FORMAT(datum, '%d') as dag
FROM blog
ORDER BY jaar DESC,
maand DESC,
dag DESC
") ;
while ($rij = mysql_fetch_array($sql_jaar))
{
if($jaar != $rij['jaar'])
{
echo "<h2>" . $rij['jaar'] . "</h2>" ;
$jaar = $rij['jaar'];
}
if($maand != $rij['maand'])
{
echo "<span style=\"font-weight: bold; margin-left: 15px;\">• " . $maanden[$rij['maand']-1]. "</span><br />" ;
$maand = $rij['maand'];
}
echo "<span style=\"margin-left: 30px;\">• " . $rij['dag']. ": " . $rij['onderwerp'] . "</span><br />" ;
}
?>
<?php
$maanden = array ( "Januari" , "Februari" , "Maart" , "April" , "Mei" , "Juni" , "Juli" , "Augustus" , "September" , "Oktober" , "November" , "December" ) ; $jaar = "" ;
$maand = "" ;
SELECT DATE_FORMAT(datum, '%Y') AS jaar,
DATE_FORMAT(datum, '%m') AS maand,
id, onderwerp, DATE_FORMAT(datum, '%d ') as dag
FROM blog
ORDER BY jaar DESC,
maand DESC,
dag DESC
" ) ;
{
if ( $jaar != $rij [ 'jaar' ] )
{
echo "<h2>" . $rij [ 'jaar' ] . "</h2>" ; $jaar = $rij [ 'jaar' ] ;
}
if ( $maand != $rij [ 'maand' ] )
{
echo "<span style=\" font-weight: bold; margin-left: 15px;\" >• " . $maanden [ $rij [ 'maand' ] - 1 ] . "</span><br />" ; $maand = $rij [ 'maand' ] ;
}
echo "<span style=\" margin-left: 30px;\" >• " . $rij [ 'dag' ] . ": " . $rij [ 'onderwerp' ] . "</span><br />" ; }
?>
En 'k zou ook niet alles outputten ergens een pagina systeem erin steken?
Gesponsorde links
Dit onderwerp is gesloten .