senters Posted June 16, 2012 Report Share Posted June 16, 2012 Piemērs: $class = ($i%4==0) ? "home-item-last" : "home-item"; $tr_start = ($i==1 || $i==5 || $i==9) ? "<tr>" : ""; $tr_end = ($i%4==0) ? "</tr>" : ""; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ... Rindā 4 elementi (preces), kurām katrs rindas pēdējais elements ir ar savu klasi un ar noslēdzošo rindas tagu </tr> Lai nebūtu manuāli jānorāda ka <tr> tag jāpievieno katram 1, 5, 9, 13 .. utt elementam, kā pierakstīt to dinamiski, līdzīgi kā uzsetoju ka home-item-last klase darbosies katram 4-ajam elementam? Link to comment Share on other sites More sharing options...
senters Posted June 16, 2012 Author Report Share Posted June 16, 2012 Uzrakstot šeit, momentā sapratu, ka jābūt - $tr_start = ($i%4==1) ? "<tr>" : ""; Link to comment Share on other sites More sharing options...
Infants Posted June 16, 2012 Report Share Posted June 16, 2012 Ja pa kruto, tad http://css-tricks.com/how-nth-child-works/ Nebūs gan 100% browser compatible... Link to comment Share on other sites More sharing options...
briedis Posted June 16, 2012 Report Share Posted June 16, 2012 Ja pa kruto, tad http://css-tricks.co...th-child-works/ Nebūs gan 100% browser compatible... Nezināju, ka ar CSS var uzģenerēt tabulas struktūru (HTML) O_o Link to comment Share on other sites More sharing options...
Infants Posted June 16, 2012 Report Share Posted June 16, 2012 Nezināju, ka ar CSS var uzģenerēt tabulas struktūru (HTML) O_o Patiešām atvainojos, galīgi neiedziļinājos jautājumā un tajā, ka pats jau saprata. <table> <?php for ($i=0; $i < count($arr); $i++): ?> <?php echo ($i%4===0) ? "<tr><td>" : "<td>"; ?> <?php echo $arr[$i]; ?> <?php echo ($i%4===3) ? "</td></tr>" : "</td>"; ?> <?php endfor; ?> </table> Link to comment Share on other sites More sharing options...
Recommended Posts