Forum Moderators: coopster
Anyways, what I was wondering is how to list alternating files...
if you have these files in a dir
1.jpg
2.jpg
3.jpg
4.jpg
5.jpg
how would show every other one
1.jpg
3.jpg
5.jpg
could one of you guys reverse engineer this script to show me where/how it lists only every other file? thanks
[edited by: jatar_k at 2:17 am (utc) on Dec. 18, 2003]
[edit reason] no urls thanks [/edit]
$evenrow = 1; // initialize prior to loop
Begin loop...
if (++$evenrow % 2) print $filename;
...end loop
<style type="text/css">tr.evenrow {background: #F6F6F6;}</style>
$table_data = '';
$evenrow = 1;
while (retrieving rows from table) {
$table_data .= '<tr';
if (++$evenrow % 2) $table_data .= ' class="evenrow"';
$table_data .= '>';
}
print $table_data;
$printstatus = 1;
foreach ....
{
if($printstatus == 1) { print ....; }
$printstatus = 3 - $printstatus;
}
Simple maths, but $printstatus will alternate between 1 and 2 with that simple equation. Of course, you cannot get it to set it to zero (which isn't the most efficient for assembly language), but for most things it is very simple.