First off ... ORDER BY column1, column2 will often give you strange results. You may want to just use a single column, or a GROUP BY clause.
As for the dynamically generated JS, this is an extremely shortened version of what I used:
print '<form action="deleter.php" method="post"><input type="submit" value="Delete" ';
print "onclick=\"if (!confirm('Are you sure you want to completely remove this item from the db?')) {return false;}\" /></form>";
Pop that into a loop, and off you go.
You could also put the JS into a function, then call the function with something like onclick="ensure();". That's probably a better solution, actually ...