Consultez la FAQ sur le ZF avant de poster une question
Vous n'êtes pas identifié.
Bonjours,
J'essaye de construire cette requette sous zend.
SELECT topic.tid, topic.title, topic.posts, topic.starter_id, topic.start_date, topic.starter_name, topic.views, topic.topic_rating_total, topic.topic_rating_hits, post.post FROM ibf_topics AS topic INNER JOIN ibf_posts AS post ON post.topic_id = topic.tid AND topic.topic_firstpost = post.pid WHERE topic.forum_id =39 AND topic.approved =1 ORDER BY topic.start_date DESC LIMIT 0 , 5
Pour l'instant j'en suis la :
$select = $this->select() ->from(array('topic'=>'ibf_topics'), array('tid', 'title', 'posts', 'starter_id', 'start_date', 'starter_name', 'views', 'topic_rating_total', 'topic_rating_hits')) ->join(array('post'=>'ibf_posts'), array('post')); $r = $this->fetchAll($select);
Quelqu'un de bienveillant pourrai m'aider a la finir ?
Merci
Hors ligne
Bonjour,
Il me semble avoir lu quelque part que dans la futur version du framework DOCTRINE serait intégré nativement donc moi perso je ne me prends plus la tete a cherché a utilisé ZEND DB.
je prends la requete est je la balance dans un query(). Plutot que de cherché à comprendre un outil qui ne sera pas maintenu dans les prochaines version.
Hors ligne
il manque des argument à ta méthode join
A+JYT
Hors ligne
Ma jointure fonctionne sans probleme.
Je veux juste l'dapter, a zend select.
damdamien Auriez vous la source de se que vous avancez ?
Hors ligne
je parle pas de ton SQl mais de l'appel à la méthode join dans ton php il te manque la clause de jointure
[lang=php]$select = $this->select() ->from( array('topic'=>'ibf_topics'), array('tid', 'title', 'posts', 'starter_id', 'start_date', 'starter_name', 'views', 'topic_rating_total', 'topic_rating_hits') ) ->join( array('post'=>'ibf_posts'), '(post.topic_id = topic.tid) AND (topic.topic_firstpost = post.pid)'), array('post') ) ->where (topic.forum_id =39) ->where (topic.approved =1) ->order('topic.start_date', 'DESC') ->limit(0 , 5); $r = $this->fetchAll($select);
si dans la clause de jointure ou dans un (nom de )champs, la chaîne contient des parenthèse elle est automatiquement transformé en expression Zend_Db_Expr
sinon il faut faire
[lang=php]new Zend_Db_Expr('post.topic_id = topic.tid AND topic.topic_firstpost = post.pid')
A+JYT
Dernière modification par sekaijin (20-07-2011 16:04:55)
Hors ligne
Alors ok.
Merci de se gros coup de main.
Par contre j'ai cette erreur
<?php class Default_Model_DbTable_News extends Zend_Db_Table { protected $_name = 'dark-rivals.ibf_topics'; protected $_primary = 'tid'; public function GetNews() { $select = $this->select() ->from( array('topic'=>'ibf_topics'), array('tid', 'title', 'posts', 'starter_id', 'start_date', 'starter_name', 'views', 'topic_rating_total', 'topic_rating_hits') ) ->join( array('post'=>'ibf_posts'), ('post.topic_id = topic.tid) AND (topic.topic_firstpost = post.pid'), array('post') ) ->where ('topic.forum_id = 39') ->where ('topic.approved = 1') ->order('topic.start_date', 'DESC') ->limit(0 , 5); $r = $this->fetchAll($select); } }
Hors ligne
Probleme resolue en rajoutant
$select = $this->select(); $select->setIntegrityCheck(false) // ....
Hors ligne