Gossamer Forum
Home : Products : Gossamer Links : Discussions :

How do I show all links by specific user in search.cgi results

Quote Reply
How do I show all links by specific user in search.cgi results
How do I show all links by a user by brower bar search ie. /cgi-bin/search.cgi?query=this&???

to show results for a specific user and list all links submitted by that user.

thanks

Last edited by:

socrates: Nov 3, 2005, 6:01 PM
Quote Reply
Re: [socrates] How do I show all links by specific user in search.cgi results In reply to
search.cgi?query=*;LinkOwner=USER

i.e;

search.cgi?query=*;LinkOwner=admin

...would list all links by "admin" Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] How do I show all links by specific user in search.cgi results In reply to
Hi Andy,

Thanks for that. Do you think there is any way to get a drop list of usernames so that people can choose from it ? Although I suppose with quite a few web sites this means a pretty long list !

Thanks,

John
Significant Media
Quote Reply
Re: [Jag] How do I show all links by specific user in search.cgi results In reply to
Hi,

Try this as a new global;

Code:
sub {

my $sth = $DB->table('Links')->select( ['DISTINCT(LinkOwner)'] ) || return $GT::SQL::error;
my $back;
$back .= qq{<select name="LinkOwner">};
while (my $user = $sth->fetchrow) {
$back .= qq{<option value="$user">$user</option>};
}
$back .= qq{</select>};

return $back;

}

...and just put in search.html, inside the <form> part Smile

(untested)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] How do I show all links by specific user in search.cgi results In reply to
Another way would be to use fetchall_list - it's a little shorter and simpler.

Code:
my @usernames = $DB->table('Links')->select('DISTINCT(LinkOwner)')->fetchall_list;

Then you can just use a simple foreach loop, or just map.

You should always call $sth->finish if you create an $sth object. I think GT::SQL does it for you as a last resort but it's better to call finish() yourself.

Last edited by:

Hargreaves: Nov 4, 2005, 5:31 AM
Quote Reply
Re: [Hargreaves] How do I show all links by specific user in search.cgi results In reply to
Erm, not really ;) You still have to do a foreach() to get those values out Tongue

>>
You should always call $sth->finish if you create an $sth object. I think GT::SQL does it for you as a last resort but it's better to call finish() yourself.
<<

Why? GT::SQL does this all for you. Thats why its a lot cleaner that trying to use DBI Angelic

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] How do I show all links by specific user in search.cgi results In reply to
Thanks, Andy and Hargreaves

I'll have to try that out. I'm still a bit worried about what it will start to look like when there are hundreds of users in a list like that.
I think I'll most probably only display it for authenticated users anyway...

I think I might also try to use Community to pull the users full name so that it's more understandable when viewing the list...

John
Significant Media
Quote Reply
Re: [Andy] How do I show all links by specific user in search.cgi results In reply to
Quote:
Erm, not really ;) You still have to do a foreach() to get those values out

I agree there's not great deal of difference, but fetchall_list is ideal for this sort of situation where you only need a list of values from one colunm and it also saves you having to deal with the $sth object.

I was thinking along the lines of:

Code:
my @users = $DB->table('Links')->select('DISTINCT(LinkOwner)')->fetchall_list;
return qq|<select name="LinkOwner">\n| . map(qq|<option value=$_">$_</option>\n|, @users) . qq|</select>\n|;

The newlines are useful for display purposes too.

Quote:
Why? GT::SQL does this all for you. Thats why its a lot cleaner that trying to use DBI

In a small code snippet it is perhaps not a big deal but calling $sth->finish() is good coding practice. GT::SQL only calls finish() when the $sth object is about to be destroyed. If you have a piece of code performing lots of queries then you are going to have lots of open handles which is not a good idea.
Quote Reply
Re: [Jag] How do I show all links by specific user in search.cgi results In reply to
You shouldn't have too many problems using the select list unless you have an incredible number of users :)

Infact you could even use a template loop to build the select list instead of mixing perl and html in the global.
Quote Reply
Re: [Hargreaves] How do I show all links by specific user in search.cgi results In reply to
Wink

I was thinking that when I saw you're comment to Andy, that it would maybe better to use a template so that I could in that way define a CSS class for the list, plus the GCommunity code for the name and lay it out nicely !

Thanks, John
Significant Media
Quote Reply
Re: [Jag] How do I show all links by specific user in search.cgi results In reply to
Hi,

Yup, to use in a loop, with my global, you could use;

Code:
sub {

my $sth = $DB->table('Links')->select( ['DISTINCT(LinkOwner)'] ) || return $GT::SQL::error;
my @back;
while (my $user = $sth->fetchrow_hashref) {
push @back, $user;
}

return { linkowner_list => \@back };

}

..and then link in the template with;

Code:
<%global_name%>
<%loop linkowner_list%>
<select value="<%LinkOwner%>"><%LinkOwner%></select>
<%endloop%>


..or with Hargreves one, something like;

Code:
sub {
my @users = $DB->table('Links')->select('DISTINCT(LinkOwner)')->fetchall_list;

my @back; my $tmphash;
map { $tmphash->{LinkOwner} = $_; push @back, $tmphash }, @users;
return { linkowner_list => \@back };
}

..and again, call with (for less confusion :P);


Code:
<%global_name%>
<%loop linkowner_list%>
<select value="<%LinkOwner%>"><%LinkOwner%></select>
<%endloop%>

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] How do I show all links by specific user in search.cgi results In reply to
I think with the second example you'd get a warning about map being used in a void context.

A template loop can be created without the need for map or a foreach loop. Simply use fetchall_hashref....

Code:
sub {
my $data = $DB->table('Links')->select('DISTINCT(LinkOwner)')->fetchall_hashref;
return { LinkOwnerList => $data }
}