davo Posted August 12, 2014 Share Posted August 12, 2014 I'm sure this is about to be one of those head banging moment which I suffer so much, but I'm trying to add some styling to a row if the user identified on that row has the 'du' role. At the moment every row styles as success but you'll see from the table that shouldn't be the case. <table class="table table-striped"> <thead> <tr> <th>Visit Date</th> <th>User Roles</th> <th>User Name</th> <th>Page ID </th> <th>DMC Page</th> <th>Country</th> </tr> </thead> <tbody> <?php $durole = "du"; // this is the role that I want highlighted in the rows foreach($page->visit_log as $visit_log_item) { $username = $users->get($visit_log_item->user_id) ; $pagename = $pages->get($visit_log_item->page_id); if ($username->hasRole($durole)) { $row = "success"; } else { $row = "info" ;} // if the user has the durole which is called du the the table row should be success else info echo "<tr class='$row'>"; echo "<td>$visit_log_item->date</td>"; echo "<td>{$username->roles}</td>"; echo "<td>{$username->name}</td>"; echo "<td>$visit_log_item->page_id</td>"; echo "<td>{$pagename->name}</td>"; echo "<td>{$pagename->DMC_country_represented->name}</td>"; echo "</tr>"; } ?> </tbody> </table> 2014-08-05 37|38 david 1312 aim-group-austria austria 2014-08-05 37|2107 agent 1100 belgium-dmc-incentive-conference-and-event-management belgium 2014-08-05 37|38 david 1312 aim-group-austria austria 2014-08-05 37|38 david 1312 aim-group-austria austria 2014-08-05 37|2107 agent 1228 green-route-south-africa south-africa 2014-08-05 37|2107 agent 1228 green-route-south-africa south-africa 2014-08-05 37 guest 1165 risbecker-norway norway 2014-08-05 37 guest 1223 unitours-maroc-morocco morocco 2014-08-05 37 guest 1343 tour-east-indonesia indonesia 2014-08-05 37 guest 1294 incentive-travel-meetings-atlanta-usa-atlanta atlanta role 'du' has a page id of 1067 which isn't included in any of the above users Link to comment Share on other sites More sharing options...
SiNNuT Posted August 12, 2014 Share Posted August 12, 2014 Not sure but might this work?: EDIT (still looking, first thought was wrong :0 ) 1 Link to comment Share on other sites More sharing options...
davo Posted August 12, 2014 Author Share Posted August 12, 2014 Thanks anyway. Got there like this in the end.. think it works:) <table class="table table-striped"> <thead> <tr> <th>Visit Date</th> <th>User Roles</th> <th>User Name</th> <th>Page ID </th> <th>DMC Page</th> <th>Country</th> </tr> </thead> <tbody> <?php $durole = "du"; // this is the role that I want highlighted in the rows $agentrole = "agent"; foreach($page->visit_log as $visit_log_item) { $username = $users->get($visit_log_item->user_id) ; $pagename = $pages->get($visit_log_item->page_id); if ($username->hasRole($durole)) { $row = "info"; } elseif ($username->hasRole($agentrole)) { $row = "danger" ;} // if the user has the durole which is called du the the table row should be success else info echo "<tr class='$row'>"; echo "<td>$visit_log_item->date</td>"; echo "<td>{$username->roles}</td>"; echo "<td>{$username->name}</td>"; echo "<td>$visit_log_item->page_id</td>"; echo "<td>{$pagename->name}</td>"; echo "<td>{$pagename->DMC_country_represented->name}</td>"; echo "</tr>"; $row = "active"; } ?> </tbody> </table> 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now