Gossamer Forum
Home : Products : DBMan : Customization :

Headlines.cgi Sort-by Problem

Quote Reply
Headlines.cgi Sort-by Problem
I can't figure out what to do in order to get my headlines.cgi script to sort in the order I want. I have used the traditional "&sb=2&so=ascend" but that doesn't do anything to change it. It appears that it is sorting in reverse ID order. I even tried "&sb=$data[2]" Any idea how I can do this?

Here is what I have:

#!/usr/local/bin/perl
### change to match your server path
### Display latest headlines ####

#### modify the path and filename of your db
$db_file_name = "/mnt/web/guide/merginet/newsite/scripts/specials/specials.db";
$db_script_url = "http://www.merginet.com/scripts/db.cgi";

open (DB, "<$db_file_name") or &cgierr("error in modify_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
my @lines = <DB>; # Slurp the database into @lines..
close DB;
my $LASTX = 9; # How many headlines do you want?
for ($i=$#lines; $i>=($#lines - $LASTX); $i--) {
chomp $lines[$i];
@data = split(/\|/,$lines[$i]);
$latest .= qq|<img src="http://www.merginet.com/newsite/images/blue_arrow_nav.gif" alt="" width="7" height="7" border="0"> <A HREF="$db_script_url?db=specials&uid=default&ID=$data[0]&sb=2&so=ascend&view_records=1"><font face=verdana,ariel,helvetica size=1 color="#FFFFFF">$data[2]</font></A><br>|;
#$data[0] is record ID, $data[2] is title in my DB
}
print $latest;

1;
####### end display latest headlines #######

The include can be found in our new site layout here:
http://www.merginet.com/newsite/index.shtml

See Blue Tag Specials in the right side column.

Here is where the page is that will list all of the items:

http://www.merginet.com/...2&view_records=1

Thanks in advance for any help.

Richard Bilger
RBilger@MERGINET.com
MERGINET.com: Emergency Responders Web Site
http://www.merginet.com
Quote Reply
Re: [RBilger] Headlines.cgi Sort-by Problem In reply to
Well, adding "sb=2" and such will be pointless, because this would be effective only if you do a search, have multiple hits and *then* sort them.
What you are doing is opening the database, read the last 9 records and then print a link to EACH record - your query strings access single records, so sorting on them is pointless.

Whatever sorting you want you have to do before you print the query-string for each link. You don't specify the sort order you want, but if you wanted to sort by ID ascending, and not descending - maybe not really useful, because perhaps you'd want the newest records appear on top -, you could use something like this:

(skipped first few lines)

open (DB, "<$db_file_name") or &cgierr("error in modify_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
my @lines = <DB>; # Slurp the database into @lines.
my %sorted_last_records;
close DB;
my $LASTX = 9; # How many headlines do you want?
for ($i=$#lines; $i>=($#lines - $LASTX); $i--) {
chomp $lines[$i];
@data = split(/\|/,$lines[$i]);
$sorted_last_records{$data[0]} = $data[2];}
foreach my $key (sort {$a <=> $b} keys %sorted_last_records ) {
$latest .= qq|<img src="http://www.merginet.com/newsite/images/blue_arrow_nav.gif" alt="" width="7" height="7" border="0"> <A HREF="$db_script_url?db=specials&uid=default&ID=$key&sb=2&so=ascend&view_records=1"><font face=verdana,ariel,helvetica size=1 color="#FFFFFF">$sorted_last_records{$key}</font></A><br>|;
}
print $latest;
kellner
Quote Reply
Re: [kellner] Headlines.cgi Sort-by Problem In reply to
Kellner,

Thanks for the help with this. I can now sort it the way I want. However when I click on a record in the list it takes me to the record but we loose the additional navigation items that are there when we access the database in the usual way. This would be the "Previous and Next Records" header and the "&html_footer" which we run in the left side column. Is there a way we can get to teh database and include these items?

Thanks.

Richard Bilger
RBilger@MERGINET.com
MERGINET.com: Emergency Responders Web Site
http://www.merginet.com
Quote Reply
Re: [RBilger] Headlines.cgi Sort-by Problem In reply to
Well, it depends on where in your html.pl the routines for displaying these items are called. With "view_records=somevalue" in the query-string, the output of the query gets usually processed by html_view_success that then calls html_record for each single record. When you call a specific record by its ID, then you will only have html_record called once.

So I guess the display code you are talking about should be printed by routines called in html_view_success; the footer is, I guess, printed by html_footer, which should be called at the end of html_view_success.

I'm not sure what the "previous" and "next" records are, and how they are computed. Are these previous and next records from amongst the last n records, or previous and next records in comparison to the current record's ID in the database? How do you usually call them?
kellner
Quote Reply
Re: [kellner] Headlines.cgi Sort-by Problem In reply to
Kellner,

Unfortunately you are talking to a real rookie here. I have been dabbling with DBMan for a few years and have used it and modified it heavily but only because I can get hints and clues from this Forum to work around a lot of my issues. Anyway...

The Previous and Next records are called from the "html_record_long" I guess as a subroutine. The final output is a table with the previous and next records on the top so the user can click to the next record in the database or the previous one which is based on the record ID.

We are currently redesigning our site which can be found here:

http://www.merginet.com/newsite/

If you use the top yellow nav bar under Shopping and select Blue Tag Specials you will see the normal way that DBMan displays the list. If you use the right column where we are using the headlines.cgi script you will see how it pulls the individual record but looses everything else.

Our intent here is to allow an assistant to input a monthly list of sale items that will populate the right column on every page. We only want the first ten or so items to display in the column in order to control the page length. The user would then be able to click over to see the entire list of available items. However, if they use the right column short list generated by headlines.cgi they will only see the item they clicked on and not be able to navigate through the rest of the list because there are no navigation tools. So that's my dilema. Any ideas?

I would also like to talk with you about your thread discussing the online content editing tool you created.

Regards,


Richard Bilger
RBilger@MERGINET.com
MERGINET.com: Emergency Responders Web Site
http://www.merginet.com
Quote Reply
Re: [RBilger] Headlines.cgi Sort-by Problem In reply to
So do you have a html_record_short *and* a html_record_long?
It would help to actually see the code. For the beginning, I'd need to take a look at html_view_success and all html_record_somethingorother routines that you have.

What would you want to know about the online editing tool? It's not done yet, and it will remain quite primitive, but I'm on my way to having a textarea with a WYSIWYG editor embedded ...
kellner
Quote Reply
Re: [kellner] Headlines.cgi Sort-by Problem In reply to
Attached (I hope) are the specials-html.pl and format.pl files for your review. I have also attached the headlines.cgi file that I am using now.

As for the content manager, we publish a twice-monthly newsletter for emergency responders and I would like our editors to be able to add the content themselves. Can we talk offline about what you are building? If it can work for us, maybe we can make a deal. Thanks.


Richard Bilger
RBilger@MERGINET.com
MERGINET.com: Emergency Responders Web Site
http://www.merginet.com
Quote Reply
Re: [RBilger] Headlines.cgi Sort-by Problem In reply to
OK, I believe the footer problem is easy:
You have plenty of calls to html_page_bottom in specials_html.pl, but no sub html_page_bottom. Most of these calls are accompanied by calls to html_footer, which is why the menu is printed; in html_view_succes, you *only* have the defunct call to html_page_bottom - replace it with "&html_footer;", and it should work. You can get rid of all the other lines "&html_page_bottom;" in the file. I suppose they are leftovers of an earlier modification :-)

As for the other problem, I'm not sure, but for a start, add this code to headlines.cgi, right above the line "$latest .= qq|<table", but inside the foreach loop:
my $nextkey = $key+1;

Then, replace the link with this code:

<A HREF="$db_script_url?db=specials&uid=default&ID=$key&sb=2&so=ascend&view_records=1&mh=1&nh=$nextkey"><font face=verdana,ariel,helvetica size=1 color="#FFFFFF">$sorted_last_records{$key}</font></a>

What puzzles me is that on your regular "specials" list, not the one pulled by headlines.cgi, you are pulling the individual records with "ID=*" in the link. Why this really gets you individual records and not several records, I have no idea :-)




kellner
Quote Reply
Re: [kellner] Headlines.cgi Sort-by Problem In reply to
Well, the "html_page_bottom" is part of the format.pl file and is actually the bottom of the page HTML. The "html_footer" is really the standard navigation links for view list, add, delete, modify etc. I moved it to the format.pl file so it showed up in the left side bar of the page.

The changes you suggested for headlines.cgi now work. I see the navigation links and the previous/next line. Now we're good to go with the exception of removing the html_footer from the rest of the specials-html.pl file. Otherwise all the add, delete, modify pages will come up with two nav link sets.

I have no idea about the ID=* part. It's what I have always used so I don't know anything about it.

Thanks for all your help.


Richard Bilger
RBilger@MERGINET.com
MERGINET.com: Emergency Responders Web Site
http://www.merginet.com
Quote Reply
Re: [kellner] Headlines.cgi Sort-by Problem In reply to
OOPS! I take that back. Now I see the previous/next but it only takes you back and forth between two records. One or the other disappears with each move. Any ideas?



Richard Bilger
RBilger@MERGINET.com
MERGINET.com: Emergency Responders Web Site
http://www.merginet.com
Quote Reply
Re: [RBilger] Headlines.cgi Sort-by Problem In reply to
Sorry I missed out on html_page_bottom. But note that you haven't added it in html_view_success. So rather than removing html_footer from all subs, try adding html_page_bottom at the end of html_view_success Wink

As for the next hits, I just noticed that the routines to print the previous and next hit bars in html_record_long are only triggered when you have more than one hit. This is weird, as html_record_long itself is only called when you have EXACTLY one hit or, if not, when you have the number of maximum hits set to one.

Try removing the line "if ($db_total_hits > 1) {" in line 303 of specials-html.pl, as well as the closing bracket in line 337 right after the table code ends and before the comment line "#Below is where you define your form".

I've also noticed that the first item in the "Blue tag specials list" with ID=1 does not match the actual entry that is pulled up when the link is clicked. Before you modified the code as I told you last time, clicking this link actually produced a list of *two* items, and not the record with ID=1. I've no idea why.
kellner
Quote Reply
Re: [kellner] Headlines.cgi Sort-by Problem In reply to
Well that didn't work. It is still only pulling one record. The reason for the two records seems to be that one record is ID=1 and the other is ID=10 It's see the 1 in ten and pulls that record.

Richard Bilger
RBilger@MERGINET.com
MERGINET.com: Emergency Responders Web Site
http://www.merginet.com
Quote Reply
Re: [RBilger] Headlines.cgi Sort-by Problem In reply to
Then add "ww=on" to the query-string. This matches "whole words" and should therefore match the exact ID number. I'll try and look at the other stuff tomorrow, as it's getting late here and my code sensors want to sleep.
kellner