Gossamer Forum
Quote Reply
Suggest category
It occured to me that Ivan's great Suggest query can be used to make an alternative listing of categories. Rather than showing search log terms, it would show category names.

I have tried this code:
Code:

my $t = $DB->table('Category');
$t->select_options('ORDER by Name DESC', 'LIMIT 25');
my $q = $IN->param('query');
my $cond = GT::SQL::Condition->new( 'Full_Name', 'LIKE', "$q%");
my $sth = $t->select($cond);
my $path = $sth->as_url($result->{Full_Name});
my $base = 'http://slashdemocracy.org/links/';
print "Content-Type: text/xml\n\n";
if ($t->hits) {
print qq|<ul class="LSRes">|;
while (my $result = $sth->fetchrow_hashref) {
print qq|<li onmouseover="liveSearchHover(this)" onclick="liveSearchClicked(this)"><a href="$base$path" name="$result->{Full_Name}">$result->{Full_Name}</a> </li>\n|;
}
print qq|</ul>|;
}

It doesn't work, but if I remove the red line, it does. That is, it does work and does show the categories, but the links only work if the category names are "straight", and does not contain spaces. Unfortunately, most of my categories contains spaces.

So, can anyone help me explaining how I get Full_Name to become worth its name? (it should be named "Full Name" ...)?

John
Quote Reply
Re: [gotze] Suggest category In reply to
I'm guessing your just calling it wrong (the as_url)...

try something like this:

my $path = $t->as_url($sth);


..... So what your trying to do is create a suggest category list for when a user adds a site (instead of displaying a full drop-down menu with every category)?

- Jonathan
Quote Reply
Re: [jdgamble] Suggest category In reply to
Thanks Jonathan.
Trust me, I have tried many combinations, including the one you suggest, but it doesn't work.
I am afraid it is a bit more complicated ...

What I am trying to do is this. When you enter a letter in the form, you get some suggestions for categories that start with that letter. I just need the links to work. And for someone to develop a script that Opera likes, but as long as it works in firefox and msie, I'm happy.

I guess this might be useful for adding links too, but am not sure how that would work.

John
Quote Reply
Re: [gotze] Suggest category In reply to
I believe you want
my $path = $t->as_url($result->{Full_Name});

Adrian
Quote Reply
Re: [brewt] Suggest category In reply to
Thanks, Adrian. It works! I knew I was on the right track ... Cool
For reference, here is the sub main I use here:
Code:
my $t = $DB->table('Category');
$t->select_options('ORDER by Full_Name DESC', 'LIMIT 25');
my $q = $IN->param('query');
my $cond = GT::SQL::Condition->new( 'Name', 'LIKE', "$q%");
my $sth = $t->select($cond);
my $base = 'http://slashdemocracy.org/links/';
print "Content-Type: text/xml\n\n";
if ($t->hits) {
print qq|<ul class="LSRes">|;
while (my $result = $sth->fetchrow_hashref) {
my $path = $t->as_url($result->{Full_Name});
print qq|<li onmouseover="liveSearchHover(this)" onclick="liveSearchClicked(this)"><a href="$base$path" name="$result->{Full_Name}">$result->{Name}</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:green;overflow:hidden;">$result->{Full_Name}</span></li>\n|;
}
print qq|</ul>|;
}

So, on to next challenge Wink

As for the green text, which produces the green output with Full_Name, I would like to show only the name of FatherID. Any suggestions?

John
Quote Reply
Re: [brewt] Suggest category In reply to
Sorry for wait... just tested it out...

You want what Adrian said, but you also want it within the while statement.

Code:

my $t = $DB->table('Category');
$t->select_options('ORDER by Name DESC', 'LIMIT 25');
my $q = $IN->param('query');
my $cond = GT::SQL::Condition->new( 'Full_Name', 'LIKE', "$q%");
my $sth = $t->select($cond);

my $base = 'http://www.magicdirectory.com/linksSQL/';
print "Content-Type: text/xml\n\n";
if ($t->hits) {
print qq|<ul class="LSRes">|;
while (my $result = $sth->fetchrow_hashref) {
my $path = $t->as_url($result->{Full_Name});
print qq|<li onmouseover="liveSearchHover(this)" onclick="liveSearchClicked(this)"><a href="$base$path" name="$result->{Full_Name}">$result->{Full_Name}</a> </li>\n|;
}
print qq|</ul>|;
}


http://www.magicdirectory.com/...sSQL/livesearch.html

Note... all my category start with m....

- Jonathan
Quote Reply
Re: [gotze] Suggest category In reply to
That is really cool thanks for sharing the code with everybody. It not only looks great on your site but it's also really useful.

Thanks,

John
Significant Media