There are a few issues but I believe things should be fixed by turning this logical operator:
AND `handle`!='NULL'"
into:
AND `handle` IS NOT NULL"
In this line and this one.
Apply those changes and let me know if it seems fixed.
As the previous fix didn't fix it, then you most likely have deleted users that have asked questions and can't be found now. Follow these steps:
1. Locate this line
2. Immediate before that line (i.e. between lines 119 and 120) add the following code:
if (is_null($user)) continue;