Can I use the results of a python SQL select query as parameters for an if/else statement in a function? If I have a DB with one column, and want to append the values of that column to a list for each row in the Select Query...I can't reference those queries in a function. For example:
db = MySQLdb.connect(host="localhost", user="root", passwd="****", db="****")
cur = db.cursor()
selectArray1 = []
cur.execute("SELECT * FROM tableName WHERE value = 'x'")
for row in cur.fetchall():
selectArray1.append(str(row[0]))
selectArray2 = []
cur.execute("SELECT * FROM tableName WHERE value = 'y'")
for row in cur.fetchall():
selectArray2.append(str(row[0]))
def function(x):
#----Question-----
#if I try to print out selectArray1[x] or selectArray2[x], why don't I get
# a return value?
#Following conditionals do not work, why not?
if selectArray1[x] == "some string":
print "The first array equals the x query"
if selectArray2[x] == "different string":
print "The second array equals the y query"
if __name__ == '__main__':
function(1)
function(2)