Jump to content

** Resolved ** Alternating row colors?


alexcmm

Recommended Posts

What's the easiest way to get alternating row colors? My code is very simple and I'm not sure if I can throw it in with ease or if I'll have some major overhauling to do... here's my code now. Thanks for your help.

[b]<?

include 'dbinfo.php';

MYSQL_CONNECT(localhost, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db( "$database") or die( "Unable to select database");

$query="SELECT * FROM $usertable ".stripslashes($mainreport)." ".stripslashes($sortby)."";
$result=mysql_query($query);
$num=mysql_numrows($result);

$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$UserName=mysql_result($result,$i,"UserName");
$AccessLevel=mysql_result($result,$i,"AccessLevel");
$status=mysql_result($result,$i,"status");
$attending=mysql_result($result,$i,"attending");
$prefix=mysql_result($result,$i,"prefix");
$firstname=mysql_result($result,$i,"firstname");
$initial=mysql_result($result,$i,"initial");
$lastname=mysql_result($result,$i,"lastname");

echo
?>[/b]
Link to comment
https://forums.phpfreaks.com/topic/27706-resolved-alternating-row-colors/
Share on other sites

aah... i remember making my pages like that... untill i found the wonder of mysql_fetch_array();

[code]
<?

include 'dbinfo.php';

MYSQL_CONNECT(localhost, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db( "$database") or die( "Unable to select database");

$query="SELECT * FROM $usertable ".stripslashes($mainreport)." ".stripslashes($sortby)."";
$result=mysql_query($query);

while($row=mysql_fetch_array){
echo $row[id];
echo $row[UserName];
echo $row[AccessLevel];
echo $row[status];
echo $row[attending];
echo $row[prefix];
echo $row[firstname];
echo $row[initial];
echo $row[lastname];
}
?>
[/code]

thats much faster, and easier on your database... also causes less problems in the long run :-)

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.