Life would be so much easier if I had the source code...
1
2
3
4
5
| return $this->table->fetchAll($this->table->select()->where("parent = ?" . $parentID)); // Moet worden return $this->table->fetchAll($this->table->select()->where("parent = ?", $parentID)); |
Ook als ik het op deze manier probeer worden de rijen allemaal teruggegeven, en niet alleen dus met die bepaalde parent:
1
| return $this->table->fetchAll("SELECT * FROM structure WHERE parent = " . $parentID); |
[ Voor 68% gewijzigd door Nic0demus op 15-05-2008 14:01 ]
Life would be so much easier if I had the source code...
1
| return $this->table->fetchAll("parent = " . $parentID); |
Maar dit zou met een Zend_Db_Select ook goed moeten gaan. Wat je kunt doen om te kijken of er wel de juiste query uitkomt is het volgende:
1
2
| $select = $this->table->select()->where("parent = ?", $parentID); echo $select; |
Dit zet het object automatisch om naar een string, die dan makkelijk te controleren is.
//Edit
Als ik trouwens het voorbeeld van jou uitvoer krijg ik wel degelijk een exception te zien.
1
| return $this->table->fetchAll("SELECT * FROM structure WHERE parent = " . $parentID); |
Heeft als resultaat
1
| SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s) |
[ Voor 24% gewijzigd door RAJH op 15-05-2008 14:16 ]
Life would be so much easier if I had the source code...
Daar heb ik geen last van, ik krijg gewoon al mn rows terugRAJH schreef op donderdag 15 mei 2008 @ 14:05:
Als ik trouwens het voorbeeld van jou uitvoer krijg ik wel degelijk een exception te zien.
PHP:
1 return $this->table->fetchAll("SELECT * FROM structure WHERE parent = " . $parentID);
[ Voor 5% gewijzigd door Nic0demus op 15-05-2008 14:19 ]
Life would be so much easier if I had the source code...
- Van welke class is $this->table?
- Hoe ziet de structure table eruit?
- De nieuwste versie, 1.5RAJH schreef op donderdag 15 mei 2008 @ 14:22:
- Welke versie van het Zend Framework gebruik je?
- Van welke class is $this->table?
- Hoe ziet de structure table eruit?
- $this->table is een Zend_Db_Table_Abstract object
- De structure table ziet er zo uit:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| CREATE TABLE `structure` ( `id` int(11) NOT NULL auto_increment, `active` int(1) NOT NULL default '0', `ids` varchar(255) default NULL, `rank` int(4) default '0', `title` varchar(255) default NULL, `htmltitle` varchar(150) default NULL, `image` int(11) default NULL, `parent` int(11) default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ; INSERT INTO `structure` (`id`, `active`, `ids`, `rank`, `title`, `htmltitle`, `image`, `parent`) VALUES (7, 1, 'home', 1, 'Home', NULL, NULL, 0), (8, 1, 'contact', 4, 'Contact', 'Contact', 0, 0), (9, 1, 'test1', 2, 'Test 1 Home', '', 2, 7), (10, 1, 'test2', 2, 'Test 2 Home', NULL, NULL, 7), (11, 1, 'test3', 3, 'Test 3 Home', NULL, NULL, 7), (12, 1, 'sub1', 1, 'Sub 1 Test 1', NULL, NULL, 9), (13, 1, 'sub2', 2, 'Sub 2 Test 1', NULL, NULL, 9), (14, 1, 'hoofdmenu', 2, 'Hoofdmenu', '', NULL, 0), (16, 1, 'rechterkolom', 0, 'Rechter kolom', '', 0, 0); |
\\Edit:
Meer info: API, Manual
Het lijkt mij allemaal in orde
[ Voor 9% gewijzigd door Nic0demus op 15-05-2008 14:37 ]
Life would be so much easier if I had the source code...
1
2
3
4
5
6
7
8
9
| require_once 'Zend/Db/Table/Abstract.php'; class StructuresModel extends Zend_Db_Table_Abstract { /** * The default table name */ protected $_name = 'structure'; } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| require_once 'Zend/Loader.php'; Zend_Loader::registerAutoload(); $db = Zend_Db::factory('Pdo_Mysql', array('host' => 'localhost', 'username' => 'root', 'password' => 'password', 'dbname' => 'test' ) ); Zend_Db_Table_Abstract::setDefaultAdapter($db); require_once 'StructuresModel.php'; $structuresModel = new StructuresModel(); echo '<pre>'; print_r($structuresModel->fetchAll('parent = 9')->toArray()); print_r($structuresModel->fetchAll($structuresModel->select()->where('parent = ?', 9))->toArray()); echo '</pre>'; |
Output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
| Array ( [0] => Array ( [id] => 12 [active] => 1 [ids] => sub1 [rank] => 1 [title] => Sub 1 Test 1 [htmltitle] => [image] => [parent] => 9 ) [1] => Array ( [id] => 13 [active] => 1 [ids] => sub2 [rank] => 2 [title] => Sub 2 Test 1 [htmltitle] => [image] => [parent] => 9 ) ) Array ( [0] => Array ( [id] => 12 [active] => 1 [ids] => sub1 [rank] => 1 [title] => Sub 1 Test 1 [htmltitle] => [image] => [parent] => 9 ) [1] => Array ( [id] => 13 [active] => 1 [ids] => sub2 [rank] => 2 [title] => Sub 2 Test 1 [htmltitle] => [image] => [parent] => 9 ) ) |
Hier werkt het dus raar genoeg wel
[ Voor 18% gewijzigd door RAJH op 15-05-2008 14:40 ]
Life would be so much easier if I had the source code...
{signature}
Life would be so much easier if I had the source code...