Gossamer Forum
Home : Products : Links 2.0 : Customization :

Search Results In Table Form

Quote Reply
Search Results In Table Form
I think this should be a simple question for some of the links experts out there.

I have set it up so that the links are all shown in a 3 X 4 table in the category pages. What I would like to do is set up the search results to be displayed the same, in a table. I am having a hard time getting anything to work in either search.cgi or site_html_templates.pl.

Anyone have an idea on how to accomplish this?

Thanks in advance,

Charlie
Quote Reply
Re: [cvance] Search Results In Table Form In reply to
The look of the search results page is set in search_result.html, modify it. If you need the links to appear different, look in search.cgi for this:

# Go through each category of links returned, and build the HTML. Store in hash %link_output.
SETOFLINKS: foreach $setoflinks (sort keys %link_results) {
my $hits = ($#{$link_results{$setoflinks}} + 1) / ($#db_cols+1);
LINK: for ($i = 0; $i < $hits; $i++) {
$link_hits++;
if (($link_hits <= $highrange) && ($link_hits >= $lowrange)) {
%tmp = &array_to_hash ($i, @{$link_results{$setoflinks}});
$link_output{$setoflinks} .= &site_html_link (%tmp) . "\n";
}
}
}



Change the red part to a new name (search-result_link), create the template how you want it to look, and add a sub for it to site_html_templates.pl. Confused?

--------------

To the board admin:

Boy, I sure like the new way to select font colors! Much better!!


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Search Results In Table Form In reply to
I'll try that, but what I need is code to go through the link_results and put them into a 3 col X 4 row table.

I am not sure how to get the script to go through the links and insert the table html code in between the links.

Charlie
Quote Reply
Re: [cvance] Search Results In Table Form In reply to
Try this. In search_result.html, put this (new in red):

<table>
<%if category_results%>
<tr><td>
<h2>Categories:</h2>
</td></tr>
<tr><td>
<ul><%category_results%></ul>
</td></tr>
<%endif%>

<%if link_results%>
<tr><td>
<h2>Links</h2>
</td></tr>
<tr><td>
<%link_results%>
</td></tr>
<%endif%>
</table>

----
In search.cgi, find this, which is creating the results. Not sure how you want it layed out (hint: what's your URL?), but here's a clue:

# Build the HTML for the category results and store it in "$category_results". Only build the html
# if we are on the first set of link results.
foreach $category (@category_results) {
if ($nh == 1) {
$cat_clean = &build_clean($category);
$linked_title = &build_linked_title ($category);
$category_results .= qq|<tr><td><li>$linked_title</td></tr>\n|;
}
$cat_hits++;
}
$cat_hits ||= 0;
$lowrange = ($nh-1) * $maxhits + 1;
$highrange = $nh * $maxhits;

# Go through each category of links returned, and build the HTML. Store in hash %link_output.
SETOFLINKS: foreach $setoflinks (sort keys %link_results) {
my $hits = ($#{$link_results{$setoflinks}} + 1) / ($#db_cols+1);
LINK: for ($i = 0; $i < $hits; $i++) {
$link_hits++;
if (($link_hits <= $highrange) && ($link_hits >= $lowrange)) {
%tmp = &array_to_hash ($i, @{$link_results{$setoflinks}});
$link_output{$setoflinks} .= &site_html_link (%tmp) . "\n";
}
}
}

# Go through the hash just built, and build the complete link output. Store in $link_results.
foreach $setoflinks (sort keys %link_output) {
$cat_clean = &build_clean ($setoflinks);
$title_linked = &build_linked_title ($setoflinks);
$link_results .= qq|<tr><td><P>$title_linked</td></tr>\n|;
$link_results .= $link_output{$setoflinks};
}

----
And then create a new look for the search result links, (different from the normal link listings) replacing the purple code above with &search_results_link and create a 'sub search_results_link' in site_html_templates.pl:

sub search_results_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.

my %rec = @_;

return &load_template ('search_results_link.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
%rec,
%globals
});
}

-----

And a new template names search_results_link.html that could look like this:

<tr><td>
<a class="link" href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Title%></a>
<%if Description%>
<span class="descript">- <%Description%></span>
<%endif%>
<small class="date">(Added: <%Date%> Hits: <%Hits%> Rating: <%Rating%> Votes: <%Votes%>) <a href="<%db_cgi_url%>/rate.cgi?ID=<%ID%>">Rate It</a></small>
</td></tr>
----

Of course, I did not test this, so your result could be strange! There looks to be an overabundance of <tr><td> tags, but you'll just have to experiment to see what is required. You can define the <td> as you need for your site, I'm just offering suggestions...


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Search Results In Table Form In reply to
Tried it, but still having problems getting the results into a 3 column table. I may be wrong, but I think I somehow need to get </tr><tr> tags in between every 3rd link to get a new row to start.

My URL is at http://www.sxywebs.com/content, and you will see how my category tables are laid out and that is how the search results should look.

I appreciate the quick replies, and all the help. You all are the greatest.

Charlie

Last edited by:

cvance: Feb 3, 2003, 9:10 AM
Quote Reply
Re: [cvance] Search Results In Table Form In reply to
Maybe something like this:

$link_results .= qq|<tr><td><P>$title_linked</td><td><P>$title_linked</td>

<td><P>$title_linked</td></tr>\n|;

Of course you'll need to adjust the other <td>'s for colspan, etc.


Leonard
aka PerlFlunkie