Welcome Guest, Not a member yet? Register   Sign In
style switch in forech loop
#1

[eluser]René Tuin[/eluser]
Hi,

I have a problem.
I want to switch a style of a certain object.
I have already done it with php only if I use the same code in CI i don't get any result.

I've the following code in my view:

Code:
<?php
$style = "even";
foreach($query as $row)
{
echo '<li id="listItem_'. $row->id .'" class="'.$style.'">
<div class="info"><b>'. $row->naam.'</b><br />'. $row->omschrijving.'</div>
</li>';

switch($style)
{
  case 'even': $style = 'even';
  break;
  case 'oneven': $style = 'oneven';
  break;                
}
}
?&gt;


Knows someone a solution to my problem.

Greetz
#2

[eluser]Dam1an[/eluser]
You could always use the alternator function in the string helper
#3

[eluser]jalalski[/eluser]
If style is 'even', then you want to switch it to 'noeven' and vice-versa. Then it will work.

HTH
#4

[eluser]René Tuin[/eluser]
[quote author="Dam1an" date="1243428701"]You could always use the alternator function in the string helper[/quote]

Thx Dam1an,

That was the helper I was looking for, i didn't know that it was the string helper.

Greetz
#5

[eluser]Dam1an[/eluser]
Thats why there's a wonderful little search box Wink
I couldn't remember if it was string or text helper either lol
#6

[eluser]xwero[/eluser]
Why need two classes if one is enough? You always have the normal style of the table row, table specific or not, and then you just add a class to the rows that need to have another style.
Code:
foreach($query as $i->$row)
{
$class = ($i%2)?' class="even"':'';

echo '<li id="listItem_'. $row->id.'"'.$class.'>
<div class="info"><b>'. $row->naam.'</b><br />'. $row->omschrijving.'</div>
</li>';

}
Just add a class to the false section of the condition if you want to add a class to the odd rows.




Theme © iAndrew 2016 - Forum software by © MyBB