justinh Posted December 16, 2008 Share Posted December 16, 2008 Okay, im displaying a directory, and i want to alternate between divs for each file in the folder.. everything works, but its displaying each file twice.. =/ heres the code <?php $d = dir($path); $icon = ''; $rowcount = 1; while (false !== ($entry = $d->read())) { if ( substr($entry, 0, 1)=='.' ) continue; $size = filesize($path.'/'.$entry); $humansize = humansize($size); $dotpos = strrpos($entry, '.'); if ($dotpos) { $ext = substr($entry, $dotpos+1); if ($ext === 'jpeg' || $ext === 'gif' || $ext === 'png') { $icon = "<img src='$entry' style='width: 48px; height: auto; vertical-align: text-top;' alt='icon' title='$entry' />"; } } while (false !== ($entry = $d->read())){ if($rowcount % 2 == 0){ print "<div id=roweven><a href='/stbs/testing/$entry'>$entry</a> ($humansize) $icon</div>\n"; ++$rowcount; } if($rowcount % 2 == 1){ print "<div id=rowodd><a href='/stbs/testing/$entry'>$entry</a> ($humansize) $icon</div>\n"; ++$rowcount; } } $icon= ''; } $d->close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/137211-row-alternating-problem/ Share on other sites More sharing options...
rhodesa Posted December 16, 2008 Share Posted December 16, 2008 you are incrementing inside your IF, so both IFs will be true: while (false !== ($entry = $d->read())){ if($rowcount % 2){ print "<div id=rowodd><a href='/stbs/testing/$entry'>$entry</a> ($humansize) $icon</div>\n"; }else{ print "<div id=roweven><a href='/stbs/testing/$entry'>$entry</a> ($humansize) $icon</div>\n"; } ++$rowcount; } edit: also, and ID attribute needs to be unique for the entire page. if you want to re-use CSS styles, use CLASS instead... Quote Link to comment https://forums.phpfreaks.com/topic/137211-row-alternating-problem/#findComment-716775 Share on other sites More sharing options...
justinh Posted December 16, 2008 Author Share Posted December 16, 2008 thanks fixed it, same div id's seem to be working just fine. Quote Link to comment https://forums.phpfreaks.com/topic/137211-row-alternating-problem/#findComment-716781 Share on other sites More sharing options...
rhodesa Posted December 16, 2008 Share Posted December 16, 2008 thanks fixed it, same div id's seem to be working just fine. they may work...but they violate XHTML/CSS standards Quote Link to comment https://forums.phpfreaks.com/topic/137211-row-alternating-problem/#findComment-716810 Share on other sites More sharing options...
premiso Posted December 16, 2008 Share Posted December 16, 2008 thanks fixed it, same div id's seem to be working just fine. they may work...but they violate XHTML/CSS standards To add to that, using a browser that conforms to standards, such as FireFox, this (I think this is true) will display different results due to the ID. IE would probably display it correctly since it violates the standards. Best coding practices is to conform to the standards, even though it "may work" later down the line it may not work. Quote Link to comment https://forums.phpfreaks.com/topic/137211-row-alternating-problem/#findComment-716831 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.