Gossamer Forum
Home : Products : Links 2.0 : Customization :

New Mod Possibility?

(Page 1 of 2)
> >
Quote Reply
New Mod Possibility?
I am trying to come up with the best flexible search options for our users. I have thought of something new that might be a great add-on and I am not sure if it is possible or if it has even been done. It is tough to explain, but here goes. As I am new to Links and CGI/Perl, I don't think I have the right stuff as of yet to make this happen. Logically, it makes sense that it would work.

What I am looking for is a drop down menu system on the search page that will only display locations which are being pulled from a new *.db file.

Let's call the new file location.db. This file would operate much like the Category.db file. The difference being that the location.db would pull different locations from the links.db and be built. So when you select Build All, this file would be written with say all location fields that you have but not allowing for duplications.

So if within your links.db file, you have:

1|Link|URL|*|*|*|Texas|*|*|*
2|Link|URL|*|*|*|Utah|*|*|*
3|Link|URL|*|*|*|Utah|*|*|*
4|Link|URL|*|*|*|Michigan|*|*|*
5|Link|URL|*|*|*|Michigan|*|*|*
6|Link|URL|*|*|*|Michigan|*|*|*
7|Link|URL|*|*|*|California|*|*|*


The new file would list only the location names once in order:

California
Michigan
Texas
Utah


This file could then be integrated into a search page thus only displaying locations that are currently within the database, not all locations which could possibly present a user with a bunch of wasted searches.

Like I said, it seems logical, but hard to explain thru the keyboard.... anyone make sense of it?


Quote Reply
Re: New Mod Possibility? In reply to
The simple solution is rather than using &build_select_field in the search codes given you before...replace it with &build_select_field_from_db, which will only pull values from the database and build a drop-down menu.

Regards,

Eliot Lee
Quote Reply
Re: New Mod Possibility? In reply to
Ok, I unerstand and I know what you mean. I was just hoping there might be away to pull this from the links.db file.

Quote Reply
Re: New Mod Possibility? In reply to
Uh...it does!

This sub is built INTO the db_utils.pl and takes values from fields in the links.db and creates a drop-down menu based on those values!

Regards,

Eliot Lee
Quote Reply
Re: New Mod Possibility? In reply to
Ok, I see. Does it keep from placing duplicate ones in the drop down?

Quote Reply
Re: New Mod Possibility? In reply to
If you know anything about Perl...check out the sub yourself and see.

Wink

Regards,

Eliot Lee
Quote Reply
Re: New Mod Possibility? In reply to
Ok, this is what I have in my site_html_templates.pl file:
sub site_html_search_form {
# --------------------------------------------------------
# This routine displays the search form.

my %rec = @_;
my $state = &build_select_field_db ("State", "$rec{'State'}");

&html_print_headers;
print &load_template ('search.html', {
term => $term,
error => $error,
state => $state
%in,
%globals
});
}


Now, it is not working of course but I am not sure where or what to add, if anything, to the search.cgi file.

Quote Reply
Re: New Mod Possibility? In reply to
You are not using the correct sub call.

You need to change the following codes:

Code:

my $state = &build_select_field_db ("State", "$rec{'State'}");


with the following:

Code:

my $state = &build_select_field_from_db ("State", "$rec{'State'}");


Good luck!

Regards,

Eliot Lee
Quote Reply
Re: New Mod Possibility? In reply to
hmmmmmm..... now I am getting
In Reply To:
fatal error: Illegal modulus zero line 343
Quote Reply
Re: New Mod Possibility? In reply to
You need to have a comma after the following line of codes:

Code:

state => $state


Like the following:

Code:

state => $state[/b],[/b]


Regards,


Eliot Lee
Quote Reply
Re: New Mod Possibility? In reply to
Arrrghhhhh!!!!! I hate little simple flubs like that.

Awesome! It works. Thanks, Eliot.

Now, a question, is there a way to set the first option to All States instead of -?

Quote Reply
Re: New Mod Possibility? In reply to
In Reply To:
Now, a question, is there a way to set the first option to All States instead of -?
Edit the following codes in the sub build_select_from_db routine in the db_utils.pl file:

Code:

$output = qq|<SELECT NAME="$name"><OPTION>---|;


to the following:

Code:

$output = qq|<SELECT NAME="$name">\n|;


WARNING: KEEP IN MIND...by doing this the first value will AUTOMATICALLY be selected when people use the search form. So, from a user's perspective, I would NOT do the above changes.

If you want to have something like Choose from one of the following:, edit the codes I gave to the following codes:

Code:

$output = qq|<SELECT NAME="$name">\n<OPTION VALUE="---">Choose one of the following:</OPTION>\n|;


Regards,

Eliot Lee
Quote Reply
Re: New Mod Possibility? In reply to
Thank you, sir!

One more mod down. Now for some sleep. God I love this!!!

Quote Reply
Re: New Mod Possibility? In reply to
You're welcome.

Regards,

Eliot Lee
Quote Reply
Re: New Mod Possibility? In reply to
How much bandwidth do you think this would use if our site was based on the Search page alone instead of the Category link pages.

I know using more than one of these drop down features would increase it but an answer for about 3 drop downs and a database of maybe 1000-2000 records is what I am looking for in the end.

Anyone?

Quote Reply
Re: New Mod Possibility? In reply to
Well...as an example...my search form, which prints out 398 values for the category search from the category.db file...uses about 11.0% CPU on average. I have this option only in my advanced search form. In Category pages, I only have two search values in the category search option.

To test this yourself...do the following:

1) Access the Net (using both your web browser and telnet).
2) Go to your search form via your web browser.
3) Execute a search.
4) At the same time, type in top in the command prompt in telnet...

You will see a read-out of CPU and Memory usage.

You can also use the Benchmark code hack, which is located in the Links: FAQs: Links 2.0. This hack will show you CPU usage and time rates for executing the script.

Regards,

Eliot Lee
Quote Reply
Re: New Mod Possibility? In reply to
This is a great feature and I am glad I implemented it.

Does anyone know how to have the drop down not display blank fileds? Such as if I use it for State names and someone from a country which doesn't have a state doesn't input one, then it puts all of those under one dropdown selection.

I would like to hide any that are blank form the dropdown.

Quote Reply
Re: New Mod Possibility? In reply to
In Reply To:
Does anyone know how to have the drop down not display blank fileds? Such as if I use it for State names and someone from a country which doesn't have a state doesn't input one, then it puts all of those under one dropdown selection.
You would have add conditional statements (if/else) in the sub build_select_field_from_db in the db_utils.pl file.

Around the following codes:

Code:

@fields = &split_decode ($_);
$selectfields{$fields[$fieldnum]}++;


is where you need to add the conditional statements.

Good luck!

Regards,

Eliot Lee
Quote Reply
Re: New Mod Possibility? In reply to
I have dropdowns on our search page. They work perfectly amd pull all of the info I am looking for from the links.db file as they should.

How can I hide the blank fields though from showing in the dropdowns. I have tried differnt If statements and nothing seems to work. Does anyone know what the If statement should be?

This is the code I have:
# Go through the database and get each unique name in that column.
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
/^\s*$/ and next LINE; # Skip blank lines
/^#/ and next LINE; # Comment Line
@fields = &split_decode ($_);
$selectfields{$fields[$fieldnum]}++;
}
close DB;

# Make a select list out of those names.
$output = qq|<SELECT NAME="$name">\n<OPTION VALUE="---">All</OPTION>\n|;
foreach $field (sort keys %selectfields) {
($field eq $value) ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<OPTION>$field\n");
}
$output .= "</SELECT>\n";
return $output;
}


Where i have bolded the text, should it not be doing that? It is the default code I posted above.

Quote Reply
Re: New Mod Possibility? In reply to
Anyone?

Quote Reply
Re: New Mod Possibility? In reply to
In Reply To:
/^\s*$/ and next LINE; # Skip blank lines
Where i have bolded the text, should it not be doing that? It is the default code I posted above.
Nice try...but no...Those codes skip blank lines in the links.db file but not blank fields.

lines =

1|Title|URL|Date|Description|....

field =

|something

I will play around with the codes and see what I come up with...no gaurantees.

Wink

Regards,


Eliot Lee
Quote Reply
Re: New Mod Possibility? In reply to
Any ideas on this??

I am still struggling with it. I have tried a few more things with no luck. This is pretty much the last thing holding me back.

If anyone knows how to have blank fields not display in drop downs that are built from the db file, please, please let me know.

Thanx.

Quote Reply
Re: New Mod Possibility? In reply to
Uh...two days is NOT long enough for people to play with codes and provide suggestions! I told you I would look at it and NO GUARANTEE!

Sorry...but you really have to be more patient or go to your local book store, buy a Perl book, and fix it yourself!

Regards,

Eliot Lee
Quote Reply
Re: New Mod Possibility? In reply to
ok, it has been just over a month now. Anyone have any idea how to do this? I am definitely not having any luck.

Any help would be appreciated.

Quote Reply
Re: New Mod Possibility? In reply to
In Reply To:
foreach $field (sort keys %selectfields) {
($field eq $value) ?
Have you tried:
Code:
foreach $field (sort keys %selectfields) {
if (!$field) { next; }
($field eq $value) ?
That would check to see if the field contained anything and if it didn't it would just get the next field from the %selectfields hash and never create an <option> line for it. It's probably too simple of a solution though, thus, Murphey says it won't work.

- Bobsie
bobsie@orphanage.com
http://goodstuff.orphanage.com/
> >