senters Posted June 16, 2012 Report 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?
senters Posted June 16, 2012 Author Report Posted June 16, 2012 Uzrakstot šeit, momentā sapratu, ka jābūt - $tr_start = ($i%4==1) ? "<tr>" : "";
Infants Posted June 16, 2012 Report Posted June 16, 2012 Ja pa kruto, tad http://css-tricks.com/how-nth-child-works/ Nebūs gan 100% browser compatible...
briedis Posted June 16, 2012 Report 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
Infants Posted June 16, 2012 Report 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>
Recommended Posts