Fixing PHP warning + fixing query.