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; ?> </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> </td>
[b]<td bgcolor="#C0C0C0">[/b]<a
href=" ./albumsongs.php?albumname=<?=strval( $row['album'] );?>&artistname=<?=strval( $row['artist'] );?>"><?=strval( $row['album'] );?></a>
</td>
<td bgcolor="#C0C0C0"><a
href="albums.php?albumname=<?=strval( $row['artist'] );?>"><?=strval( $row['artist'] );?></a> </td>
td bgcolor="#C0C0C0">66 </td>
</tr>
Re: How to use diffrent color for each record output
try this
PHP Code:
if(($numbers%2) == 1)
{
//colour 1
}
else
{
//colour 2
}
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; ?> </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> </td>
<td bgcolor="#C0C0C0"><a
href=" ./albumsongs.php?albumname=<?=strval( $row['album'] );?>&artistname=<?=strval( $row['artist'] );?>"><?=strval( $row['album'] );?></a>
</td>
<td bgcolor="#C0C0C0"><a
href="albums.php?albumname=<?=strval( $row['artist'] );?>"><?=strval( $row['artist'] );?></a> </td>
<td bgcolor="#C0C0C0">66 </td>
</tr>
<? break;
case "artist": ?>
<tr>
<td width="5%" bgcolor="#C0C0C0"><? echo $numbers; ?> </td>
<td width="35%" bgcolor="#C0C0C0"><a
href="albums.php?albumname=<?=strval( $row['artist'] );?>"><b><?=strval( $row['artist'] );?></b>
</a> </td>
<td width="10%" bgcolor="#C0C0C0">467 </td>
</tr>
<? break;
case "album": ?>
<tr>
<td bgcolor="#C0C0C0"><? echo $numbers; ?> </td>
<td bgcolor="#C0C0C0"><a
href="./albumsongs.php?albumname=<?=strval( $row['album'] );?>&artistname=<?=strval( $row['artist'] );?>"><?=strval( $row['album'] );?></a> </td>
<td bgcolor="#C0C0C0"><a
href="albums.php?albumname=<?=strval( $row['artist'] );?>"><?=strval( $row['artist'] );?></a> </td>
<td bgcolor="#C0C0C0">276 </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