I am a python/web2py newbie. I am trying to create a user friendly web search form for clients that connects to our existing Oracle DB and executes a query based on search criteria put in the form by users.
For example, user will fill out the form saying first_name = "John" , last_name="Smith" and when they submit, it will output for them all the information in the database for John Smith.
I am using DAL to connect to the existing external Oracle DB
my_db = DAL('oracle://username/password@Database')
I am using simple FORM to create the form as I could not figure out how to use SQLFORM etc. because those seem to want me to create/define tables which I do not want to do as the table already exists and which do not want to modify. This is purely a query program.
My display_form is something like this
def display_form():
form = FORM('First Name' INPUT(_name='first_name'),
'Last Name' INPUT (_name='last_name'),
INPUT(_type='submit'))
if form.accepts(request,session):
session.first_name = request.vars.first_name
session.last_name = request.vars.last_name
redirect(URL('next'))
return dict (form=form)
def next():
sql = "SELECT * from Table 1 where field1 = session.first_name and field2 = session.last_name "
rows = my_db.executesql(sql)
return locals()
Then the next.html is
{{extend 'layout.html'}}
<h1>Here is your query results.</h1>
{{=rows}}
This works fine except that output is in this format:
[(field1:value1,field2:value2)] etc.
What is the easiest way to output this in a html table output?
I would also like to provide xls output option.
Thanks.