Gossamer Forum
Home : Products : DBMan : Customization :

Alternating Coloring in Short View

Quote Reply
Alternating Coloring in Short View
Hi there,

I notice that under the html.pl file, in the "html_view_success" subroutine, there's this:
for (0 .. $numhits - 1) {
print "<TR><TD>";
&html_record (&array_to_hash($_, @hits));
print "</TD></TR>";
++$i;
}

And I have the short/Long display mod installed.
Can i actually write something that, let's say, have a specific color for the row (e.g. Change the above <TD> tag to <TD Bgcolor="Somecolor"> when the hit is an odd, and some other color when the hit is an even)
so that it makes an alternating color look? I don't know which variables will keep track of the Hit number and what perl function will be able to check whether that number is an odd or even.....

Thanks!
Quote Reply
Re: Alternating Coloring in Short View In reply to
$row=0;
for (0 .. $numhits - 1) {
$row++;
print "<TR>";
if ($row == 1) {
print '<TD bgcolor="this_color">';
}
elsif ($row == 2) {
print '<TD bgcolor="that_color">';
$row=0;
}

&html_record (&array_to_hash($_, @hits));
print "</TD></TR>";
++$i;
}


------------------
WFMY-TV Webmaster

[This message has been edited by Chris071371 (edited December 17, 1999).]
Quote Reply
Re: Alternating Coloring in Short View In reply to
Hi there, and thanks!

However, now I discovered that where changing the color of the <TD> actually has an effect is within the "html_record", not "html_view_success".

Is it possible to pass the $row variable into the "html_record" subroutine, or is there another method?

Thanks!
Quote Reply
Re: Alternating Coloring in Short View In reply to
I don't understand what you are trying to do. You may have to draw it out for me or give me a link to an example.

------------------
WFMY-TV Webmaster
Quote Reply
Re: Alternating Coloring in Short View In reply to
These are the codes I have (with using the Compact Table View Mod from the Resource Center):

Code:
if ( $db_total_hits == 1 ) {
%rec = &array_to_hash(0, @hits);
&html_record_long(%rec);
print qq|
<P>
<CENTER>
<$font>
<B><a href=\"$ENV{'HTTP_REFERER'}\">Back to Previous Page</a></B>
</CENTER></font>|;
}
else {
&html_record_row(&array_to_hash($_, @hits));
for (0 .. $numhits - 1) {
if ($i%2) {
print qq|<tr bgcolor="#DDDDDD">|;
}
else {
print qq|<tr bgcolor="#EEEEEE">|;
}
&html_record(&array_to_hash($_, @hits));
print "</tr>";
++$i;
}
print "</TABLE></DIV></CENTER>";
}

Regards.

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Alternating Coloring in Short View In reply to
How about for templates? I have links working to give me alternate colors using templates, but I can't seem to figure out dbman using templates.

Any ideas?
Thanks!
Adam
Quote Reply
Re: Alternating Coloring in Short View In reply to
In the sub html_view_success routine (in the dbm_templates.pl) file, you use the same codes. But rather than using print qq|, you replace that with $variable. (Whatever $variable that TimRyan used in that sub-routine.)

So, the codes would look like the following:

Code:
if ( $db_total_hits == 1 ) {
%rec = &array_to_hash(0, @hits);
&html_record_long(%rec);
}
else {
&html_record_row(&array_to_hash($_, @hits));
for (0 .. $numhits - 1) {
if ($i%2) {
$variable .= qq|<tr bgcolor="#DDDDDD">|;
}
else {
$variable .= qq|<tr bgcolor="#EEEEEE">|;
}
&html_record(&array_to_hash($_, @hits));
$variable .= qq|</tr>|;
++$i;
}
$variable .= qq|</TABLE></DIV></CENTER>|;
}

Best of luck!

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Alternating Coloring in Short View In reply to
Good..at least you figured out what you needed to do.

You're welcome.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Alternating Coloring in Short View In reply to
Thanks for the help Eliot. Here is what my final solution was. I do not have the compact forms mod installed so it's a little different.

Code:
if ( $db_total_hits == 1 ) {
%rec = &array_to_hash(0, @hits);
$view_success_N_html_record .= qq|<tr bgcolor="#EEEEEE">|;
$view_success_N_html_record .= &html_record(%rec);
$view_success_N_html_record .= "</tr>";
}
else {

for (0 .. $numhits - 1) {
if ($i%2) {
$view_success_N_html_record .= qq|<tr bgcolor="#DDDDDD">|;
}
else {
$view_success_N_html_record .= qq|<tr bgcolor="#EEEEEE">|;
}

$view_success_N_html_record .= &html_record (&array_to_hash($_, @hits));
$view_success_N_html_record .= "</tr>";
++$i;
}
}
$view_success_N_html_record .= "</TABLE></DIV></CENTER>";

[This message has been edited by anr (edited April 02, 2000).]