emehrkay Posted November 10, 2006 Share Posted November 10, 2006 this was pissing me off so i moved on a while ago, but now im back to revisit it. - it may be because i am holding on to this one way of trying to accomplsih it, anyway...i am outputting a table and one of the columns is 'Location' (its semi-grouped by this field). i need to alternate colors between different locations. so i am tryingif($i > 0){if($data[$i]->site_name != $data[$i-1]->site_name){//switch here}}but i can not figure out the logic to save my life.any ideas? thanks Link to comment https://forums.phpfreaks.com/topic/26858-alternate-row-colors-by-blocks/ Share on other sites More sharing options...
ralph4100 Posted November 10, 2006 Share Posted November 10, 2006 usually the mod operator is best for this but your question is hard to understand. try to explain more fully what you are trying to do Link to comment https://forums.phpfreaks.com/topic/26858-alternate-row-colors-by-blocks/#findComment-122835 Share on other sites More sharing options...
blear Posted November 10, 2006 Share Posted November 10, 2006 I would use $thisSite and $lastSite variables. Your conditional on if statement would be if($thisSite!=$lastSite) and you'd have to add a $lastSite='NONSENSICALDATATOREDUCECHANCESOFBEINGTHESAMEASMYFIRSTROW'; before the $i loop. Then, the last line of the loop should read $lastSite=$thisSite.Personally, I always have trouble getting array indices working inside of conditionals and/or any other function. Especially with -> operator. So, I assign the values I want inside that array to temporary variables before I actually use them in any fundtion. Link to comment https://forums.phpfreaks.com/topic/26858-alternate-row-colors-by-blocks/#findComment-122837 Share on other sites More sharing options...
emehrkay Posted November 10, 2006 Author Share Posted November 10, 2006 ralph, i have a table and when it is printed out, the rows are generally grouped by location. i want one group to be white, then when the location changes i need for that group to be blue. then back to white for the next and so on. blear, i believe that i tried your approach before. the best i could do was get the first row of the new loaction to be different while the rest were the same as the first block. -im stuck Link to comment https://forums.phpfreaks.com/topic/26858-alternate-row-colors-by-blocks/#findComment-122854 Share on other sites More sharing options...
emehrkay Posted November 13, 2006 Author Share Posted November 13, 2006 i figured it out, its a little long but it gets ti done. thanks for the help[code=php:0] $rowColor = 'x'; //row color basic definition for($i = 0; $i < $count; $i++){ $name = $data[$i]->last_name .", ".$data[$i]->first_name; $class = $data[$i]->course_type_name; $location = $data[$i]->site_name; $dates = LmsEnroll::format_date($data[$i]->class_start_date) ." - ". LmsEnroll::format_date($data[$i]->class_end_date); $checkBox = $data[$i]->class_id.'|'.$data[$i]->person_id; /** * Row Colors **/ if($i > 0){ if($data[$i]->site_name != $data[$i-1]->site_name){ $rowColor = ($rowColor == 'x') ? 'y' : 'x'; }elseif($data[$i]->site_name == $data[$i-1]->site_name){ $rowColor = ($rowColor == 'x') ? 'x' : 'y'; } }[/code] Link to comment https://forums.phpfreaks.com/topic/26858-alternate-row-colors-by-blocks/#findComment-124028 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.