Gossamer Forum
Home : Products : Links 2.0 : Customization :

3 Hours and still haven't got anywhere - Need some help

Quote Reply
3 Hours and still haven't got anywhere - Need some help
Hi all, I have a little problem with some customisation of the the Top x Category Mod. Basically the mod puts the the top 3 links by hits at the top of each category. I have the following code in nph_build.cgi :-

sub build_top_x {
# --------------------------------------------------------------
# Mod introduces the top x links in each category added 07/01/01

my ($category) = @_;
my (@values, $top_cat, @topx, $topxhtml, $count);
$original = $db_sort_links;
$db_sort_links = $db_hits;
@topx = &build_sorthit (@{$links{$category}});
$db_sort_links = $original;
$topxhtml = qq~<table cellpadding="2" cellspacing="0" border="0"><tr><td colspan=4>~;
$topxhtml = qq~<b><font color=black>Top 3 Category Downloads:</b></td></tr>\n~;
my $display = 3;
(($#topx+1) / ($#db_cols+1) >= 3) or $display = ($#topx+1)/($#db_cols+1);
for ($i = 0; $i < $display; $i++) {
%tmp = &array_to_hash ($i, @topx);
$count = $i+1;
$topxhtml .= qq~<tr><td valign="top"><font color=blue>$count.</font></td><td valign="top">~;
$topxhtml .= qq~<a href="$db_cgi_url/detail.cgi?$db_key=$tmp{$db_key}"><font color=blue>$tmp{'Title'}</font></a></td>~;
$topxhtml .= qq~<td></td><td><font color=black>$tmp{'Hits'} Downloads</font></td></tr>\n~;
}
$topxhtml .= qq~</table>~;
return $topxhtml;
}


The problem is I want to added an image to the mod but with an if statement. I already have the image in its own field under ImageURL. I have the mod working well for the link.html template in which I use the following code.

<%if ImageURL%>
<img border=0 src=<%ImageURL%> width=100 height=123>
<%endif%>
<%ifnot ImageURL%>
<img border=0 src=<%build_image_url%>/na.jpg width=100 height=123>
<%endif%>

The problem is I now want to insert the same code into the sub build_top_x mod in between the title and the hits count. I have tried a few things but I am getting no where. I tried the following code but when I rebuild I get an 404 error in my admin panel, I tried a few changes after that but with the same result.

Code I have tried:

%tmp = &array_to_hash ($i, @topx);
$count = $i+1;
$topxhtml .= qq~<tr><td valign="top"><font color=blue>$count.</font></td><td valign="top">~;
$topxhtml .= qq~<a href="$db_cgi_url/detail.cgi?$db_key=$tmp{$db_key}"><font color=blue>$tmp{'Title'}</font></a></td>~;

if ($tmp{'ImageURL'}) {
$topxhtml .= qq~<img border=0 src=$tmp{'ImageURL'} width=100 height=123>~; }
else {
$topxhtml .= qq~<img border=0 src=$build_image_url/na.jpg width=100 height=123>~; }


$topxhtml .= qq~<td></td><td><font color=black>$tmp{'Hits'} Downloads</font></td></tr>\n~;
}
$topxhtml .= qq~</table>~;
return $topxhtml;


Can anyone lend a hand here as my head is now spinning.......
Also whats the difference between qq~ and qq| and when should either be used.
Quote Reply
Re: [stu2000] 3 Hours and still haven't got anywhere - Need some help In reply to
Could be as simple as adding double quotes?

Code:
$topxhtml .= qq~<img border=0 src="$tmp{'ImageURL'}" width=100 height=123>~; }


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] 3 Hours and still haven't got anywhere - Need some help In reply to
I eventually managed to solve it by going back to the original mod and starting again. The codes I posted for the original mod above worked well, so I copied it and started to play around, well I though I copied it, but I missed out the } at the end.

Code:
$topxhtml .= qq~</table>~;
return $topxhtml;
}