switched val & key in query foreach