blondine Posted May 20, 2010 Report Share Posted May 20, 2010 (edited) ideja ir tada, sakartot un izvadit sekojosaa kartibaa kaa Edited May 26, 2010 by blondine Quote Link to comment Share on other sites More sharing options...
briedis Posted May 20, 2010 Report Share Posted May 20, 2010 Kur problēma, cik tālu esi tikusi? Vispirms, sakārto datumu augoshaa secībā (ar mysql kvēriju ORDER BY), tad ej cauri katram ierakstam. Tiklīdz sākas jauns gads, tā sākam jaunu <ul> elementu, drukājam li elementus līdz sākas jau cits gads. Tad aizveram </ul> elementu, atveram nākošo ul un atkal drukājam līdz cits gands... Kaut kā tā... $ierpiekseais = ..; while($row = mysql-fetch){ if $row-tagadejais gads != $ieprieksejais{ //izdrukajam atzimi, ka sacies jauns gads $ieprieksejais = $row-tagadejais gads } drukajam <li>$row tagadejais datums</li> } Quote Link to comment Share on other sites More sharing options...
ABU Posted May 21, 2010 Report Share Posted May 21, 2010 Varbūt tev vispirms vajag tabu <ul> un </ul> iznest pirms foreach cikla? Savādāk katram il tagam ir savs ul tags. print '<ul>'; foreach ($posts as $path => $timestamp) { . . . . . . } print'</ul>'; Un kas tev tieši nestrādā? Quote Link to comment Share on other sites More sharing options...
briedis Posted May 21, 2010 Report Share Posted May 21, 2010 <? $arr = array( "2009. 1", "2009. 2", "2010. 3", "2010. 4", "2010. 5", "2011. 6", "2011. 7", "2011. 8"); //$arr jābūt sakārtotam masīvam! $prev = false; foreach($arr as $item){ list($y, $n) = explode(". ", $item); if($prev != $y){ if($prev !== false){ //Ja šis nav pirmais, tad jāaizver pēdējais echo "</ul>"; } $prev = $y; echo "<h1>$y. gads</h1><ul>"; } echo "<li>$n</li>"; } //Ja ir izvadījies vismaz viens, tad jāaizver <ul> if($prev !== false){ echo "</ul>"; } ?> 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.