Change color

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • de Beers

    Change color

    Does anyone know how I would make each row of the result a different color:
    here is what I have:

    <html>
    <head>
    <title>Untitl ed Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="#FFFFF F" text="#000000">
    <?
    $connection=mys ql_connect("loc alhost", "bla bla", "bla bla") or die
    ("could not connect");
    mysql_select_db ("yorkbia2_dbna me");
    $result = mysql_query("SE LECT * FROM Board");
    echo "<table border=0, table width=200%, bgcolor=#FFFFFF >\n";
    while ($myrow = mysql_fetch_row ($result)) {
    printf("<tr><td %s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>
    <td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</tr>\n",
    $myrow[0], $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5],
    $myrow[6], $myrow[7], $myrow[8], $myrow[9], $myrow[10]);
    }
    echo "</table>\n";
    ?>
    </body>
    </html>


  • Shane Lahey

    #2
    Re: Change color

    On Fri, 28 May 2004 21:43:20 -0700, "de Beers" <fdgdf@yahoo.ca > wrote:
    [color=blue]
    >Does anyone know how I would make each row of the result a different color:
    >here is what I have:
    >
    ><html>
    ><head>
    ><title>Untitle d Document</title>
    ><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    ></head>
    >
    ><body bgcolor="#FFFFF F" text="#000000">
    ><?
    >$connection=my sql_connect("lo calhost", "bla bla", "bla bla") or die
    >("could not connect");
    >mysql_select_d b("yorkbia2_dbn ame");
    >$result = mysql_query("SE LECT * FROM Board");
    >echo "<table border=0, table width=200%, bgcolor=#FFFFFF >\n";
    >while ($myrow = mysql_fetch_row ($result)) {
    > printf("<tr><td %s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>
    > <td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</tr>\n",
    > $myrow[0], $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5],
    > $myrow[6], $myrow[7], $myrow[8], $myrow[9], $myrow[10]);
    >}
    >echo "</table>\n";
    >?>
    ></body>
    ></html>
    >[/color]

    $rowColor1 = '#000000';
    $rowColor2 = '#555555';
    $pos = 0;

    while ($myrow = mysql_fetch_row ($result))
    {
    $rowColor = ($pos++ % 2) ? $rowColor1 : $rowColor2;

    // do everything else here.....
    // use your $rowColor where applicaple
    }

    Comment

    Working...