Jump to content

Alternating colors


todayme

Recommended Posts

I have a couple of problems with this example one is the variables dont work they just show as the variable name instead of the variables contents like this $Location grrrrrrrrr the other is no alternate colors.........one other person had the same problem with this example.  But there was no one returned to resolve it......  Anybody got any ideas.

echo '<table width="100%" border="0" cellpadding="4" cellspacing="0">

    <tr>

        <td width="110">Event Date</td>

        <td>Event Title</td>

 

    </tr>';

 

// Define your colors for the alternating rows

 

$color1 = "#CCFFCC"; 

$color2 = "#ffffff"; 

$row_count = 0;

 

// Perform an statndard SQL query:

 

 

 

$sql_events = mysql_query("SELECT * FROM _Leads WHERE LINKID = '$userid'")

or die(mysql_error());

 

 

// We are going to use the "$row" method for this query. This is just my preference.

 

while ($row = mysql_fetch_array($sql_events)) {

    $Industry = $row["Industry"];

    $Location = $row["Location"];

 

 

 

    /* Now we do this small line which is basically going to tell 

    PHP to alternate the colors between the two colors we defined above. */

 

    $row_color = ($row_count % 2) ? $color1 : $color2;

 

    // Echo your table row and table data that you want to be looped over and over here.

 

    echo '<tr>

    <td width="110" bgcolor="$row_color" nowrap>

    $Location</td>

    <td bgcolor="$row_color">

    <a>$Industry</a></td>

    </tr>';

 

    // Add 1 to the row count

 

    $row_count++;

}

 

// Close out your table.

 

echo '</table>';

 

 

 

mysql_close($db);

 

 

Link to comment
https://forums.phpfreaks.com/topic/40854-alternating-colors/
Share on other sites

Try it now:

 

<?php

echo '<table width="100%" border="0" cellpadding="4" cellspacing="0">
    <tr>
        <td width="110">Event Date</td>
        <td>Event Title</td>
   
    </tr>';

// Define your colors for the alternating rows

$color1 = "#CCFFCC"; 
$color2 = "#ffffff"; 
$row_count = 0;

// Perform an statndard SQL query:
$sql_events = mysql_query("SELECT * FROM _Leads WHERE LINKID = '$userid'")
or die(mysql_error());


// We are going to use the "$row" method for this query. This is just my preference.
while ($row = mysql_fetch_array($sql_events))
{
    $Industry = $row['Industry'];
    $Location = $row['Location'];



    /* Now we do this small line which is basically going to tell 
    PHP to alternate the colors between the two colors we defined above. */

    $row_color = ($row_count % 2) ? $color1 : $color2;

    // Echo your table row and table data that you want to be looped over and over here.

    echo '<tr>
    <td width="110" bgcolor="'.$row_color.'" nowrap>'.$Location.'</td>
    <td bgcolor="'.$row_color.'">
    <a>'.$Industry.'</a></td>
    </tr>';

    // Add 1 to the row count

    $row_count++;
}

// Close out your table.

echo '</table>';

mysql_close($db);

?>

 

 

Orio.

Link to comment
https://forums.phpfreaks.com/topic/40854-alternating-colors/#findComment-197796
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.