Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: DB search results using DBI...execute

by jamroll (Beadle)
on Mar 04, 2017 at 21:49 UTC ( #1183676=note: print w/replies, xml ) Need Help??


in reply to Re: DB search results using DBI...execute
in thread DB search results using DBI...execute

my oops - here's the "search_item" code...
sub search_item($$$$) { #* # to search for a list of user IDs which match one criteria (ie: eye +_clr=1) # searches can only happen with the logged in user # we must not include the logged in user in the search results! # nor should we include those that are banned or security level 888 +or higher #* my ($db, $usersRef, $name, $value) = @_; # a DBH && a reference to a + list of users to search && the name of the item to search for && the + value the named item must be my @searched; # a list of UIDs which match the given name=value pair +s my $query = "select ID from users where $name='$value';"; my $resultsRef = sql_execute($db, $query); if ($resultsRef) { if (ref $resultsRef eq "ARRAY") { # we have multiple hits! my @array = @$resultsRef; foreach my $hit (@array) { # $hit is a hash reference. my %hash = %$hit; push @searched, $hash{ID}; } } else { # we only have one hit! my %hash = %$resultsRef; push @searched, $hash{ID}; } } # it is very possible to have an empty "searched" array. # this is totally ok. return @searched; # an array of uid's which matched the specified cr +iteria, minus the logged in user's uid #usage: my @results = search_item($db, \@uList, "eyes", "1"); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1183676]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2021-12-08 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (34 votes). Check out past polls.

    Notices?