form = cgi.FieldStorage()
db = MySQLdb.connect(host="127.0.0.1",user="root",passwd="",db="houses")
cursor = db.cursor()
cursor.execute("SELECT * FROM HOME")
rows = cursor.fetchall()
for row in rows:
the above is my .py for querying my database set up in xampp with phpadmin
sql! i have a drop down menu in my html and this cgi returns all the
information from my "Home" table. I want to my usr choice to correspond with
the row in my database and not to return all the info only what the user is
looking for. lets say my drop down menu is home1,home2.home3 and usr selects
home1 how do i code that just the information with home1 returns??
SELECT home1 FROM HOME
yes sorry looking at my comment -not much sense made! basically I have a html
page with a drop down list. I then created my phpadmin database (xampp-sql)
and populated the database. so lets say you go to my webpage and there is a
drop down list of choices say: house1,house2,house3 and as a user you select
on one of these options(lets say house2) and you get back information just
regarding house2(this information is what I have set up on the database-lets
say on a table called HOME)
Then I set up my cgi. and from my cgi I cal call all the info on HOME table
but what I want is to correspond each option to the user with the row of
information the user choice is link to. so for each option on my drop down
menu I want a cgi to assign each option with the specific information(home1 is
a row on the HOME table and if the user selects home1 I want it to return
information regarding only home1 so essentially I will be returning a row of
?????? reallystuck.com!!! and would appreciate help!!
Not sure if I inderstood right, but there's some info missing here. Isn't it
just basic SQL?
cursor.execute('''SELECT * FROM `HOMES` WHERE your_column = %s''', my_usr_mutation)
hi thanks for your help - it turns out that the problem was with the phpadmin
however I do have another question. On my html I have multiple drop down
menus. the user must choose the two options from two drop down menus and then
click on 'submit'.
so lets say the html is : choice 1: houseA>houseB>houseC(this is the list)
choice 2: Red>Blue>green
user must select an option from both lists and then click submit to get
what would be the sql command for this??
in the cgi would I first assign the names : my_usr_choice=form.value ????
You would need to extract both values from your form, something like:
house = form['House'].value
colour = form['Colour'].value
and they call with something like:
cursor.execute('''SELECT * FROM `HOMES` WHERE your_column1 = %s AND your_column2 = %s''', (house, colour))
Perhaps, have a look at the API: http://mysql-
thats great thanks you !!
would you know an SQL statement to search a whole database?
il create a simple search box in html and then connect it to a cgi with an sql
statement to search all of my database in phpadmin depending on what the user
is looking for. if the user types in house1 and clicks search they will get a
return on all info with house1 from the database??
This is getting out of the scope of using MySQLdb. I would suggest you to
learn SQL first.
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.