Creating an sqlite database search engine with python
Question: I have an sqlite database with 2 tables. I need to create a cgi search engine
for the database, with 2 options in a drop-down menu: Name & Keyword.

If the option is Keyword, the 1st table is searched for a matching keyword (in
any column). If the option is Name, the 1st column of the 2nd table is
searched for an exact match.

I have created the cgi web interface with a search box, and the drop-down
menu, that saves the input search term. Now I am stuck as to how I can program
my cgi script to do a search of the database based on the input term, and
display the results to screen as a table.

Below are the relevant parts of my script:

    
    
    import cgi
    
    """set up the content type, open the html, title, and body"""
    
    print '<form action=search.cgi>'
    print '<select name=\'dropdown\'>'
    print   '<option> Name </option>'
    print   '<option> Keyword </option>'
    print '</select>'
    
    print '<input type=\'text\' name=\'desc\' size=\'25\'>'
    print '<button type="submit"> Go </button>'
    print '</form>'
    
    args = cgi.FieldStorage()
    desc = args.getfirst("desc")
    dropdown = args.getfirst("dropdown")
    

And here is where I need help:

    
    
    if dropdown == 'Keyword':
        ...
    elif dropdown == 'Name':
        ...
    

Thanks in advance for any help!


Answer: It seems you just need to do some pretty basic sqlite database operations. The
[stdlib documentation](http://docs.python.org/2/library/sqlite3.html) should
get you most of the way. It has also links for more resources to help you do
more comprehensive SQL queries.

