Cibiņš Posted March 12, 2012 Report Share Posted March 12, 2012 (edited) Pašlaik man ir šāds skripts <? $query = mysql_query("SELECT * FROM table WHERE active = '1' ORDER BY add_date ASC")or die(mysql_error()); if (!mysql_num_rows($query)) { ?> <li>Nav datu!</li> <? } else { while ($row = mysql_fetch_assoc($query)) { $name=$row['vards']; $esc_name=mysql_real_escape_string($name); $stripsl_name=stripslashes($esc_name); ?> <li class="pamatklase"><? echo $stripsl_name; ?></li> <? } } ?> Ja ieraksti ir 6, tad izvada <li class="klase first">Vards 1></li> <li class="klase first">Vards 2></li> <li class="klase first">Vards 3></li> <li class="klase first">Vards 4></li> <li class="klase first">Vards 5></li> <li class="klase first">Vards 6></li> Kā panākt lai veidotos šāds skripts <li class="klase first">Vards 1></li> <li class="klase last">Vards 2></li> <li class="klase first">Vards 3></li> <li class="klase last">Vards 4></li> <li class="klase first">Vards 5></li> <li class="klase last">Vards 6></li> kur katram otrajam pirmajam ierakstam tiek piešķirta klase "first" un katram otrajam-"last"?? Edited March 12, 2012 by Cibiņš Quote Link to comment Share on other sites More sharing options...
briedis Posted March 12, 2012 Report Share Posted March 12, 2012 Jēziņ, tiešām nevar izdomāt pats? :) Izmanto vienu mainīgo kā skaitītāju. Quote Link to comment Share on other sites More sharing options...
abc Posted March 12, 2012 Report Share Posted March 12, 2012 http://www.devchunks.com/web-development/using-the-php-modulus-operator/ Quote Link to comment Share on other sites More sharing options...
Cibiņš Posted March 12, 2012 Author Report Share Posted March 12, 2012 (edited) A nah viņš tagad dublicē ierakstus?? <? $query = mysql_query("SELECT * FROM table WHERE active = '1' ORDER BY add_date ASC")or die(mysql_error()); if (!mysql_num_rows($query)) { ?> <li>Nav datu!</li> <? }else { $values=array('item', 'item last'); $i=0; while ($row = mysql_fetch_assoc($query)){ $name=$row['vards']; $esc_name=mysql_real_escape_string($name); $stripsl_name=stripslashes($esc_name); foreach ($values as $value){ $i++; ?> <li class="<? echo $value; ?>"><? echo $stripsl_name; ?></li> <? } }}?> Edited March 12, 2012 by Cibiņš Quote Link to comment Share on other sites More sharing options...
briedis Posted March 12, 2012 Report Share Posted March 12, 2012 Tev ir cikls ciklā, ko tad tu gaidīji? Quote Link to comment Share on other sites More sharing options...
daGrevis Posted March 13, 2012 Report Share Posted March 13, 2012 Pietiks «programmēt». P.S. Tu pēc kverija izpildes escape'o mainīgo no SQLi. Quote Link to comment Share on other sites More sharing options...
mad182 Posted March 13, 2012 Report Share Posted March 13, 2012 (edited) <? $query = mysql_query("SELECT * FROM table WHERE active = '1' ORDER BY add_date ASC")or die(mysql_error()); $i = 0; if (!mysql_num_rows($query)) { echo '<li>Nav datu!</li>'; } else { while ($row = mysql_fetch_assoc($query)) { echo '<li class="klase '.(($i++&1) ? 'last' : 'first').'">'.$row['vards'].'</li>'; } } ?> Kaut kā tā... Edited March 13, 2012 by mad182 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.