Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Searching a text file

by monoxide (Beadle)
on Nov 14, 2004 at 03:03 UTC ( #407652=note: print w/replies, xml ) Need Help??


in reply to Re: Searching a text file
in thread Searching a text file

Thanks Zaxo, but how would i write an SQL query that would let me search for a string in any field in the table? also i am not such a big fan of DBD::CSV.

Replies are listed 'Best First'.
Re^3: Searching a text file
by tachyon (Chancellor) on Nov 14, 2004 at 09:18 UTC

    Why would you *want* to search for a string in any field? You last field looks like a boolean (on off) your 4th field looks boolean too (male female). If you are searching for emails you would not really want to look there....

    Presumably you have a data entry form. This can also be a search form, just add a button that says search. When a user enters data in one or more fields and clicks search all you do is make a query like:

    $sth = $dbh->prepare('SELECT foo,bar,baz FROM widget WHERE foo=? AND b +ar=? AND baz=?'); $sth->execute($foo,$bar,$baz);

    where you dynamically construct the WHERE clause depending on how many fields the user enters data into. To search *all* the fields for the one string the syntax would simply be OR, not AND and include all the fields you want to search.....

    $sth = $dbh->prepare('SELECT foo,bar,baz FROM widget WHERE foo=? OR ba +r=? OR baz=?'); $sth->execute($str,$str,$str);

    DBD::SQLite might suit you better.

    cheers

    tachyon

Re^3: Searching a text file
by CountZero (Bishop) on Nov 14, 2004 at 11:34 UTC
    If you want to search for a string in any field, just concatenate all your fields into one field and write an SQL which does a "LIKE" search (with appropriate "%" before and after the search term) on that single field.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2021-02-24 18:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?