Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][Zend Framework] Zliczanie rekordów
Forum PHP.pl > Forum > Przedszkole
sweter
Witam,
powiedzmy, że mam taki zapytanie do MySQL'a:
  1. $znajomi = new Znajomi_uzyt();
  2. $this->view->znajomi = $znajomi->fetchAll('id_uzyt='.$id_uzyt);

Jak policzyć ile rekordów zwróciła metoda fetchAll() ?
Tylko proszę, nie odsyłajcie mnie do Googli, bo nic tam nie znalazłem.
nospor
przeciez fetchAll zwraca tablice. Nie umiesz policzyc elementów tablicy?

http://pl.php.net/manual/pl/function.count.php
zend
Bynajmniej nie tablice, a obiekt smile.gif Ale liczbę elementów liczy się tak samo
nospor
Obiekt powiadasz.....
  1. public function fetchAll($style = null, $col = null)
  2. {
  3. $data = array();
  4. if ($style === Zend_Db::FETCH_COLUMN && $col === null) {
  5. $col = 0;
  6. }
  7. if ($col === null) {
  8. while ($row = $this->fetch($style)) {
  9. $data[] = $row;
  10. }
  11. } else {
  12. while (false !== ($val = $this->fetchColumn($col))) {
  13. $data[] = $val;
  14. }
  15. }
  16. return $data;
  17. }

Gdzie tu widzisz obiekt? winksmiley.jpg
zend
Bitwa na metody? aarambo.gif

Mój kod pochodzi z Zend_Db_Table_Abstract, a Twój z Zend_Db_Statement, czego sweter na 99% nie używa smile.gif
  1. /**
  2.   * Fetches all rows.
  3.   *
  4.   * Honors the Zend_Db_Adapter fetch mode.
  5.   *
  6.   * @param string|array|Zend_Db_Table_Select $where OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
  7.   * @param string|array $order OPTIONAL An SQL ORDER clause.
  8.   * @param int $count OPTIONAL An SQL LIMIT count.
  9.   * @param int $offset OPTIONAL An SQL LIMIT offset.
  10.   * @return Zend_Db_Table_Rowset_Abstract The row results per the Zend_Db_Adapter fetch mode.
  11.   */
  12. public function fetchAll($where = null, $order = null, $count = null, $offset = null)
  13. {
  14. if (!($where instanceof Zend_Db_Table_Select)) {
  15. $select = $this->select();
  16.  
  17. if ($where !== null) {
  18. $this->_where($select, $where);
  19. }
  20.  
  21. if ($order !== null) {
  22. $this->_order($select, $order);
  23. }
  24.  
  25. if ($count !== null || $offset !== null) {
  26. $select->limit($count, $offset);
  27. }
  28.  
  29. } else {
  30. $select = $where;
  31. }
  32.  
  33. $rows = $this->_fetch($select);
  34.  
  35. $data = array(
  36. 'table' => $this,
  37. 'data' => $rows,
  38. 'readOnly' => $select->isReadOnly(),
  39. 'rowClass' => $this->getRowClass(),
  40. 'stored' => true
  41. );
  42.  
  43. $rowsetClass = $this->getRowsetClass();
  44. if (!class_exists($rowsetClass)) {
  45. require_once 'Zend/Loader.php';
  46. Zend_Loader::loadClass($rowsetClass);
  47. }
  48. return new $rowsetClass($data);
  49. }
nospor
Zend_Db_Statement smile.gif

Jak ja robie var_dump($rows), gdzie $rows pochodzi z czegos ala:
  1. $stmt = $this->db->query('.......');
  2. $rows = $stmt->fetchAll();
  3. var_dump($rows);

To mam tablice smile.gif
zend
A z mojego trzeba zrobić, żeby było tablicą
  1. var_dump($table -> fetchAll() -> toArray());
nospor
Dobra, uznajmy to za remis smile.gif
W ramach wyleczenia ran wojennych ja zaproszę cię na piwko a ty mnie na garnczek miodku smile.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.