Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-12-2008, 07:26 PM
Junior Member
 
Join Date: Mar 2008
Posts: 8
Default join problems. output isn't in the variable

function viewAction() {
$this->view->title='Příspěvek';
$this->post=new Post();
$select=$this->post->select();
$select->setIntegrityCheck(false);
$select->from($this->post,array('id','name','activity','id_no','post', 'attachment','date_format(created,"%d.%m.%Y") AS datum'));
$select
->join(array('u'=>'users'),'u.id=posts.user_id')
->join(array('cat'=>'category'),'posts.category_id= cat.id','category')
->join(array('loc'=>'locality'),'loc.id=posts.local ity_id')
->order("created DESC")->limit(1);
echo $select;
//po->limit(5,5);
//Zend_Debug::dump($select);
$this->view->post=$this->post->fetchAll();

}

creates me a query like this:

SELECT `posts`.`id`, `posts`.`name`, `posts`.`activity`, `posts`.`id_no`, `posts`.`post`, `posts`.`attachment`, date_format(created,"%d.%m.%Y") AS `datum`, `u`.*, `cat`.`category`, `loc`.* FROM `posts` INNER JOIN `users` AS `u` ON u.id=posts.user_id INNER JOIN `category` AS `cat` ON posts.category_id=cat.id INNER JOIN `locality` AS `loc` ON loc.id=posts.locality_id ORDER BY `created` DESC LIMIT 1

however, when i vardump $this->view->post i don't get data from joined tables.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-13-2008, 07:25 PM
xentek's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 112
Default

First off, I recommend moving all of the querying stuff to your model file, and use that method in your Controller.

2nd, you may find that you need to set the results of $this-post-fetchAll(); to another variable, and then set that var to your view for it to give you your data (I'm assuming when you vardump the view var, you're getting metadata about your table, and not the data).

Also, vardump in the view, and work on $this->post and not $this->view->post.

HTH,
__________________
- xentek
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-14-2008, 11:03 AM
Junior Member
 
Join Date: Mar 2008
Posts: 8
Default

yep, youre right, xentek. i figured it out yesterday. my mistake indeed was that i was using fetchRow(); instead of fetchRow($select); :-)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:19 AM.