Results 1 to 3 of 3

Thread: How to use diffrent color for each record output

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    How to use diffrent color for each record output

    I am using this code to output the search result for song title and currently it uses same color for all maches.What i want to use this color #FFB951 and #C0C0C0
    for background of each row but not same color for consucative rows . In another word if there are 4 records i want first one to be #C0C0C0 and second #FFB951 and 3th #C0C0C0 and 4th #FFB951 .Could any one tell me how this can be done.

    PHP Code:
    $numbers=0;
    while($row = mysql_fetch_assoc($result))
    {

     $numbers++; // counting number of records
    ?>

    <?
    switch ($m):
     case "title": ?>


    <tr>
            <td bgcolor="#C0C0C0"><? echo $numbers; ?>&nbsp;</td>
            <td bgcolor="#C0C0C0"><a
            href="javascript:newWindow('./playlistfromdbtotextfile.php?songid=<?=strval$row['id'] );?>')"><img
            src="./images/Speaker.gif" alt="Listen to this Song"
            border="0" width="16" height="16"
            longdesc="Listen to this Song"></a> <b><?=strval$row['songname'] );?></b>&nbsp;</td>
            [b]<td bgcolor="#C0C0C0">[/b]<a
            href=" ./albumsongs.php?albumname=<?=strval$row['album'] );?>&artistname=<?=strval$row['artist'] );?>"><?=strval$row['album'] );?></a>&nbsp;

      
            </td>
            <td bgcolor="#C0C0C0"><a
            href="albums.php?albumname=<?=strval$row['artist'] );?>"><?=strval$row['artist'] );?></a> </td>
            td bgcolor="#C0C0C0">66&nbsp;</td>
        </tr>

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: How to use diffrent color for each record output

    try this

    PHP Code:
    if(($numbers%2) == 1)
    {
    //colour 1
    }
    else
    {
    //colour 2


  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to use diffrent color for each record output

    Quote Originally Posted by john tindell
    try this

    PHP Code:
    if(($numbers%2) == 1)
    {
    //colour 1
    }
    else
    {
    //colour 2

    but what to do with <td bgcolor="#C0C0C0"> parts ? i have blocks of code with <td bgcolor="#C0C0C0"> on it ! where to place your code ?



    PHP Code:
    while($row = mysql_fetch_assoc($result))
    {
       
     
    $numbers++; // counting number of records

    ?>

    <?
    switch ($m):
     case "title": ?>


    <tr>
            <td bgcolor="#C0C0C0"><? echo $numbers; ?>&nbsp;</td>
            <td bgcolor="#C0C0C0"><a
            href="javascript:newWindow('./playlistfromdbtotextfile.php?songid=<?=strval$row['id'] );?>')"><img
            src="./images/Speaker.gif" alt="Listen to this Song"
            border="0" width="16" height="16"
            longdesc="Listen to this Song"></a> <b><?=strval$row['songname'] );?></b>&nbsp;</td>
            <td bgcolor="#C0C0C0"><a
            href=" ./albumsongs.php?albumname=<?=strval$row['album'] );?>&artistname=<?=strval$row['artist'] );?>"><?=strval$row['album'] );?></a>&nbsp;

      
            </td>
            <td bgcolor="#C0C0C0"><a
            href="albums.php?albumname=<?=strval$row['artist'] );?>"><?=strval$row['artist'] );?></a> </td>
            <td bgcolor="#C0C0C0">66&nbsp;</td>
        </tr>

     


                            
     <? break;
     case "artist": ?>
     <tr>
            <td width="5%" bgcolor="#C0C0C0"><? echo $numbers; ?>&nbsp;</td>
            <td width="35%" bgcolor="#C0C0C0"><a
            href="albums.php?albumname=<?=strval$row['artist'] );?>"><b><?=strval$row['artist'] );?></b>
            &nbsp;</a> </td>
            <td width="10%" bgcolor="#C0C0C0">467&nbsp;</td>
    </tr>
     <? break;
     case "album": ?>

    <tr>
            <td bgcolor="#C0C0C0"><? echo $numbers; ?>&nbsp;</td>
            <td bgcolor="#C0C0C0"><a
            href="./albumsongs.php?albumname=<?=strval$row['album'] );?>&artistname=<?=strval$row['artist'] );?>"><?=strval$row['album'] );?></a>&nbsp;</td>
            <td bgcolor="#C0C0C0"><a
            href="albums.php?albumname=<?=strval$row['artist'] );?>"><?=strval$row['artist'] );?></a> </td>
            <td bgcolor="#C0C0C0">276&nbsp;</td>
        </tr>




    <? break;
     default: ?>
     this is some default html

    <? endswitch; ?>

                             

    <?


    } =====end of my while
    i want some thing like the pic:

    Last edited by tony007; May 22nd, 2006 at 01:10 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width