Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: how do i construct a sql select statement, where i want to get the where clauses out of an array

by George_Sherston (Vicar)
on Aug 25, 2001 at 21:25 UTC ( [id://107844]=note: print w/replies, xml ) Need Help??


in reply to how do i construct a sql select statement, where i want to get the where clauses out of an array

One More Way To Do It:
use DBI; my $dbh = DBI->connect("DBI:mysql:database=your_db"); my $where = "(id = '" . join ("' OR id = '", @ids) . "')"; my $sth = $dbh->prepare("SELECT * FROM event WHERE $where");
Then loop through the db output with
while ($ref = $sth->fetchrow_hashref) { &do_stuff_with($ref->{'db_col_u_like'}); }
NB when @ids is empty your SQL statement is SELECT * FROM event WHERE (id = '') which may be just what you want.

§ George Sherston
  • Comment on Re: how do i construct a sql select statement, where i want to get the where clauses out of an array
  • Select or Download Code

Replies are listed 'Best First'.
Re: how do i construct a sql select statement, where i want to get the where clauses out of an array
by pitbull3000 (Beadle) on Aug 25, 2001 at 21:30 UTC
    bout the problem of an empty array i already thought, but the array shouldnt be empty it is filled with values out of a form, which invokes the script... but u never know... would it be some solution to put a zero as first id in the array, cause the zero wont be an id in the db table
      Yes, or just put the whole thing in an if (@ids) { ... }loop - which would make it work quicker when @ids was empty

      § George Sherston

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-25 10:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found