Using Select queries in python mysql as parameters for if/else block
<p>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:</p>

<pre><code>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)
</code></pre>

<p>Please see this link: <a href="http://stackoverflow.com/questions/14835852/convert-sql-result-to-list-python">Convert sql result to list python</a></p>

<p>Basically, you want something similar to this:</p>

<p><code>list(cur.fetchall())</code></p>

python mysql database list function