swatisonee Posted September 28, 2007 Share Posted September 28, 2007 Hi, I found this snippet of code on the following site, but i'm not sure what it means. How can an html call $r ? Any suggestions pl ? Thanks. ..... just simply stores your colors in table and then directly alternate them into your output html code: $query_color = "SELECT * FROM colors ORDER BY RAND() LIMIT 1"; $result = mysql_query($query_color); $r = mysql_fetch_object($result); The original code was print '<table width="650" border="0" cellpadding="2" cellspacing="1">\n'; print '<TR><td width="50%">Name</td><td width="50%">Email</td></TR>\n'; for($i = 0; $i < $numofrows; $i++) { $row = @mysql_fetch_array($result); if($i % 2) { print '<TR bgcolor="#333333">\n'; } else { print '<TR bgcolor="#444444">\n'; } print "<td>" . $row['name']."</td><td>" . $row['email']."</td>\n"; print "</TR>\n"; } print "</table>\n"; http://www.scriptplayground.com/tutorials/php/Alternating-Row-Color/ Link to comment https://forums.phpfreaks.com/topic/71024-alternating-row-colour/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.