mysql - Can't manage to return 100 results in Python -
so i'm trying 100 results mysql database via python. here's got far
cursor = db.cursor() cursor.execute("select author, quote quotes order rand() limit 100") row in cursor.fetchall(): quote = row[1] author = row[0] return jsonify(quote=quote, author=author) when give run, 1 result, so
{ "author": "helen keller", "quote": "faith strength shattered world shall emerge light." } i'm trying return 100, not 1 quote. ideas?
you returning on first pass through for loop. why 1 result.
instead of loop, this:
def testdb(): cursor = db.cursor() cursor.execute("select author, quote quotes order rand()") return jsonify(data=cursor.fetchall()) you remove for loop before return statement. if have fetchall() in there twice, without second query, second attempt produce empty list.
Comments
Post a Comment