NoSalt Posted November 23, 2008 Share Posted November 23, 2008 Hello All I am at the end of my rope trying to figure out why this isn't working and I was hoping one of you could help me. Here is what I am trying: <table> <?php for($j=0; $j<sizeof($dataArray){ if($dataArray[$j]){ ?> <tr class="active_<?php echo ($j%2); ?>"><td class="padRight" nowrap><?php echo $infoArray[$j]; ?>:</td><td class="padLeft"><?php echo $dataArray[$j]; ?></td></tr> <?php $j++ } } ?> </table> Whenever I load this page my local server pegs out and I have to restart Apache. I really think this should work but is just doesn't. Can someone please tell me what I am doing wrong? Thanks for reading Link to comment https://forums.phpfreaks.com/topic/133928-solved-loop-help-needed/ Share on other sites More sharing options...
Mark Baker Posted November 23, 2008 Share Posted November 23, 2008 You need to increment $j within your definition of the for loop, not within the loop itself <table> <?php for($j=0; $j<sizeof($dataArray);$j++){ if($dataArray[$j]){ ?> <tr class="active_<?php echo ($j%2); ?>"><td class="padRight" nowrap><?php echo $infoArray[$j]; ?>:</td><td class="padLeft"><?php echo $dataArray[$j]; ?></td></tr> <?php } } ?> </table> Whenever I load this page my local server pegs out and I have to restart Apache. I really think this should work but is just doesn't. Can someone please tell me what I am doing wrong? Thanks for reading Link to comment https://forums.phpfreaks.com/topic/133928-solved-loop-help-needed/#findComment-697146 Share on other sites More sharing options...
NoSalt Posted November 23, 2008 Author Share Posted November 23, 2008 Rats ... You can probably see what I am attempting to do. I want to alternately color the table rows for clear viewing on the page. However, some of the array variables are going to be 'null' and I don't want to increment $j for those variables because I will have two rows in succession be the same color. Any tips for pulling this off? Thanks for reading and replying Link to comment https://forums.phpfreaks.com/topic/133928-solved-loop-help-needed/#findComment-697149 Share on other sites More sharing options...
Mark Baker Posted November 23, 2008 Share Posted November 23, 2008 <?php $k = 0; for($j=0; $j<sizeof($dataArray);$j++){ if($dataArray[$j]){ ?> <tr class="active_<?php echo ($k%2); ?>"><td class="padRight" nowrap><?php echo $infoArray[$j]; ?>:</td><td class="padLeft"><?php echo $dataArray[$j]; ?></td></tr> <?php } $k++; } } ?> Link to comment https://forums.phpfreaks.com/topic/133928-solved-loop-help-needed/#findComment-697155 Share on other sites More sharing options...
NoSalt Posted November 23, 2008 Author Share Posted November 23, 2008 OK ... now I feel like a moron. Thank you very much, that worked great. I guess I needed a fresh set of eyes after looking at this for so long. Have a good one. Link to comment https://forums.phpfreaks.com/topic/133928-solved-loop-help-needed/#findComment-697165 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.