Running loops and doing a select statement each time [especially with rand()] is a bad idea. here is what I think is a better approach.
1. Run ONE SELECT query to get all of the vtext values from the rsample table for the groupname
2. Populate those results into an array
3. User array_shuffle() to randomize the results of the array
4. Run the loops for $i & $j like you have now, but create a simple INSERT statement like this
INSERT INTO decks (id, dnumber, vtext) VALUES (:id, :dnumber, :vtext)
5. Define the vtext value on each loop using array_shift() which will remove and return the first value in the array
$stmt -> bindValue(':vtext', array_shit($vtextValuesAry));Go to the full post