todayme Posted March 2, 2007 Share Posted March 2, 2007 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 More sharing options...
Orio Posted March 2, 2007 Share Posted March 2, 2007 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 More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 try using this echo '<tr> <td width="110" bgcolor="'.$row_color.'" nowrap> '.$Location.'</td> <td bgcolor="'.$row_color.'"> <a>'.$Industry.'[/url]</td> </tr>'; Link to comment https://forums.phpfreaks.com/topic/40854-alternating-colors/#findComment-197797 Share on other sites More sharing options...
todayme Posted March 2, 2007 Author Share Posted March 2, 2007 Thanks guys just a beginner but I see what I am doing wrong just got to put into words. Link to comment https://forums.phpfreaks.com/topic/40854-alternating-colors/#findComment-197798 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.