Jump to content
php.lv forumi

Specifiska klase pēc 2 ierakstiem


Cibiņš

Recommended Posts

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 by Cibiņš
Link to comment
Share on other sites

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 by Cibiņš
Link to comment
Share on other sites

<?
$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 by mad182
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...