I am making a web application using HTML, python and a MYSQL database. I currently have two tables: one that stores users and the other that stores flashcards.
I want to add the feature of ‘practising’ flashcards by displaying a random flashcard from the database one at a time but am unsure how I could approach this.
At first, I was thinking that I could generate a random number and display the card with the respective flashcard ID, but the ‘FlashID’ doesn’t reset per user.
SQLController.execute(f"SELECT count(*) FROM flashcards WHERE UserID = '{UserID}'")
MaxQuestionsList=(list(SQLController))
MaxQuestions = str(MaxQuestionsList[0])
RandCard = randint(1,int(MaxQuestions[1]))
SQLController.execute(f"SELECT Question, Answer FROM flashcarcs WHERE FlashID = '{RandCard}'")
2
Answers
I don’t know Python, but couldn’t you just do a random function on a primary key from your sql database? Like an id of some sort.
You could do SELECT * FROM flashcards WHERE UserID= ‘{UserId]’
then do like a randint based on the ID of the SQL Row.