It is necessary to group all the dates in the database when outputting using GROUP BY wrote a function that gives the error Fatal error: Call to a member function fetch() on a non-object I can not understand what it is

  // Соединение с БД $db = Db::getConnection(); $result = $db->query("SELECT id_shop, day FROM product_order GROUP BY day"); $i = 0; $dayList = array(); while ($row = $result->fetch()) { $dayList[$i]['id_shop'] = $row['id_shop']; $dayList[$i]['day'] = $row['day']; $i++; } return $dayList; 
  • after you call query, check for errors, and if they are, display messages about these errors. or enable error output at the connection level. In any case, the DB most likely returns you some kind of error, you just ignore it and therefore do not see and do not know what is happening - Mike
  • And it is very likely that the database error is related to the fact that by grouping by day you are trying to output the value of the id_shop field, but the database does not know id_shop which particular records from the set for the group should be returned (you can specify this by using the min / max function to id_shop) ru.stackoverflow.com/a/599802/194569 - Mike
  • PS: note also that there is a fetchAll method and there is no need to write a loop. - teran
  • @teran can be more detailed - Aziret Kadykeev

0