Welcome Guest, Not a member yet? Register   Sign In
formatting query results
#6

[eluser]xwero[/eluser]
[quote author="Steve Grant" date="1223910304"]
Your best bet is probably to use a for loop rather than foreach, as you then effectively create your own array indexing.

Something like...
Code:
<ul>
&lt;?php for($i = 0; $i < count($items); $i++): ?&gt;
  &lt;?php $item = $items->result(); ?&gt;
  <li&lt;?php if(($i + 1) % 3 == 0): ?&gt; class="classname"&lt;?php endif; ?&gt;>&lt;?php echo $item->name; ?&gt;
&lt;?php endfor; ?&gt;
</ul>
[/quote]
You can do it with a foreach loop by using the key.
Code:
<ul>&lt;?php foreach($items as $i=>$item): ?&gt;
<li&lt;?php if(($i+1) % 3 == 0) echo ' class="classname"' ?&gt;>&lt;?php echo $item->name ?&gt;</li>&lt;?php endforeach ?&gt;
</ul>


Messages In This Thread
formatting query results - by El Forum - 10-13-2008, 03:15 AM
formatting query results - by El Forum - 10-13-2008, 04:05 AM
formatting query results - by El Forum - 10-13-2008, 04:09 AM
formatting query results - by El Forum - 10-13-2008, 04:16 AM
formatting query results - by El Forum - 10-13-2008, 06:44 AM
formatting query results - by El Forum - 10-13-2008, 06:55 AM
formatting query results - by El Forum - 10-13-2008, 07:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB