Jump to content

PHP & CSS Switch Question


bgnm2000

Recommended Posts

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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 '';
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.