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

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -