bgnm2000 Posted February 5, 2008 Share Posted February 5, 2008 Hey everyone, I'm a complete newb when it comes to PHP, so I apologize if I sound like a bozo asking this. I'm trying to edit a script I have to show search results in varying color, I.E. one gray, one white, one gray, one white etc. A friend told me this can be done through a switch and loop. If I could see a quick demonstration (the code) of something like this, I'm pretty sure I'd be able to figure out the rest. thanks for your time! and thanks in advance for any help! -bgnm Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted February 5, 2008 Share Posted February 5, 2008 well you can use a variety of methods depending on how you coded it, can you show us some code so that we can help you edit it? because if you are going to display information using a loop such as foreach() or while() you can just do something like this: <table> <?php $x = 1; // lets say you have a foreach() loop foreach(/* Your Data*/){ if($x == 1){ $bg = "background-color: #888888;"; $x++; } else{ $bg = "background-color: #FFFFFF;"; $x--; } echo '<tr style="'. $bg .'"><td>Data</td></tr>'; } ?> </table> Quote Link to comment Share on other sites More sharing options...
bgnm2000 Posted February 5, 2008 Author Share Posted February 5, 2008 the current code in this script is: function display_list($listing) { $color1 = 'listing'; $color2 = 'listing_alt'; $row_count = 0; if ($listing) { foreach($listing as $key => $value) { $row_color = ($row_count % 2) ? $color1 : $color2; echo '<div id="listing">'; echo '<div class="left" id="listing_title"><span class="right"><a href="'.SITE_URL.'index.php?userid='.$listing[$key]["owner_id"].'">' . $listing[$key]["company"].'</a></span><a href="'.SITE_URL."job.php?job=".$listing[$key]['id'].'"><strong>' . $listing[$key]["title"].'</strong></a></div>'; echo '<div id="listing_details">'; $my_desc = desc_truncate($listing[$key]['description'], 100); echo '<span class="style1">('.LANG_LISTING_POSTED.' '.$listing[$key]['added'].')</span> '.$listing[$key]["location"].'</div>'; echo '<div id="listing_description">'; echo "<span class='listing_description'>".$my_desc."</span>"; echo "</div>"; echo "</div>"; if ($_SESSION['userid'] == $listing[$key]['owner_id'] || $_SESSION['valid_role'] == 1) {echo " <a href='".SITE_URL."edit.php?job=".$listing[$key]['id']."' class='edit'>".LANG_LISTING_EDIT."</a>";} if ($_SESSION['valid_role'] == 1) { if ($listing[$key]['status'] == 0) { echo " | <a href='".SITE_URL."scripts/activate.php?job=".$listing[$key]['id']."'>".LANG_LISTINGS_ACTIVATE_LISTING."</a>"; } else { echo " | <a href='".SITE_URL."scripts/suspend.php?job=".$listing[$key]['id']."' class='suspend'>".LANG_LISTING_SUSPEND."</a>"; } } echo "</span>"; $row_count++; } } else { echo ''; } } Quote Link to comment 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.