{Solved}:How can i give everyline a special css?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mekha
Forum Contributor
Posts: 112
Joined: Sat Mar 31, 2012 6:50 am

{Solved}:How can i give everyline a special css?

Post by mekha »

How can i give everyline a special css?
i have a categories:
for example:

devnetwork
google
yahoo
..
i need every category (line)
in a different style ?
maybe "while" but i dont know how to use?!
Last edited by mekha on Fri Apr 13, 2012 9:35 am, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How can i give everyline a special css?

Post by Celauran »

Where are these categories coming from? How are you displaying them? Please post some code and provide a little more detail about what you're trying to do.
mekha
Forum Contributor
Posts: 112
Joined: Sat Mar 31, 2012 6:50 am

Re: How can i give everyline a special css?

Post by mekha »

Code: Select all


<?php
  $result3 = get_all_cats();	
			
  foreach($result3 as $lkey=>$lval)

  {
	
	

       echo '<li class="color"><a href="categories.php?cat='.$lval['Id'].'"><img src="images/page_bg.gif" width="4" height="4" border="0" alt=""> '.$lval['category_name'].'</a></li>';



  }
						
?>

this is my code that shows the category...
i need every line of category be another background color (class)
..
http://topline.me/shop2

if u see the categories above (left)...the same style..
i need
1
2
1
2
1
2

1=style1
2=style2
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How can i give everyline a special css?

Post by Celauran »

So you don't want every line to have a different class, you just want to alternate between 2.

Code: Select all

<?php

$result3 = get_all_cats();    

$i = 1;
foreach($result3 as $lkey=>$lval)
{
    $class = ($i % 2 == 0) ? 'class1' : 'class2';
    echo '<li class="'.$class.'"><a href="categories.php?cat='.$lval['Id'].'"><img src="images/page_bg.gif" width="4" height="4" border="0" alt=""> '.$lval['category_name'].'</a></li>';
    $i++;
}

?>
mekha
Forum Contributor
Posts: 112
Joined: Sat Mar 31, 2012 6:50 am

Re: How can i give everyline a special css?

Post by mekha »

GREAT MAN ... THANK YOU!
Post Reply