hiiii all,

Can anyone please help me regarding this ....

i have table with 2 cloumns in a database "details"

Name Age
john 26
Mary 18
Nancy 20

i want to get only the Age in an array.

I tired in this way:

db=MySQLdb.connect(user="root",passwd="my",db="mydb")
cursor=db.cursor()# prepare a cursor object using cursor() method
abc = "SELECT Age FROM Details "
try:
# Execute the SQL command
cursor.execute(abc)

*********************
for row in cursor
print row
array[row]************ # Commit your changes in the database
db.commit()
except:
db.rollback() # Rollback in case there is any error

db.close() # disconnect from server


I want ages 26,16,20 in an array like array =

Please help me out.........i tried in many ways but i am not able to do this......

I don't use MySQL, but try using this line instead and see what happens.

abc = "SELECT * FROM Details"
records = cursor.fetchall()

and is the table named "Details" or "mydb".

So you want to modify

for row in cursor
    print row
##
##   to
for row in records:
    print row

Thanks.... that works.... but i am getting

but i should get it as [26 18 20]

as a string.....'26'......... actuallt data type of ages is varchar is that the problem? Do you know how to convert array like this into [26 18 20]

because i have to plot graph for these value, array will not allow me to do that

This article has been dead for over six months. Start a new discussion instead.