PDA

Click to See Complete Forum and Search --> : How to use diffrent color for each record output


tony007
May 22nd, 2006, 06:49 AM
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.

$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>
<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>

john tindell
May 22nd, 2006, 08:34 AM
try this


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

tony007
May 22nd, 2006, 08:36 AM
try this


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 ?



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:

http://i5.photobucket.com/albums/y180/method007/row.jpg