Solved

SELECT statement in Zend_Framework

Posted on 2008-06-18
2
367 Views
Last Modified: 2013-12-12
I have th following code that will display all the rows in a table.  I want to use a custom select statement to display data from more than one table.   How can I do this with zend_db_table ? Or do i need to use another class?


$this->view->title = "Showing All";
		$items = new Items();
		$this->view->items = $items->fetchAll();	
 
 
 
 
require_once 'Zend/Db/Table/Abstract.php';
 
class Items extends Zend_Db_Table_Abstract {
	/**
	 * The default table name 
	 */
	protected $_name = 't_items';
 
 
 
<p><a>Displaying Short View</a></p>
<table>
<tr>
     <th>nickname</th>
     <th>serial</th>
     <th>&nbsp;</th>
</tr>
<?php foreach($this->items as $item) : ?>
<tr>
     <td><?php echo $this->escape($item->nickname);?></td>
     <td><?php echo $this->escape($item->serial);?></td>
     <td>
          <a href="<?php echo $this->url(array('controller'=>'index',
              'action'=>'edit', 'id'=>$item->id));?>">Edit</a>
          <a href="<?php echo $this->url(array('controller'=>'index',
              'action'=>'delete', 'id'=>$item->id));?>">Delete</a>
     </td>
</tr>
<?php endforeach; ?>
</table>

Open in new window

0
Comment
Question by:sean-keys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
Alex-w474 earned 500 total points
ID: 21818492
Look for Zend_Db_Select examples in manual: http://framework.zend.com/manual/en/zend.db.select.html
Or use select object derived from the table: http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.fetch-all
$table = new Bugs();
 
$select = $table->select();
$select->where('bug_status = ?', 'NEW')
       ->join('accounts', 'accounts.account_name = bugs.reported_by')
       ->where('accounts.account_name = ?', 'Bob');
 
$rows = $table->fetchAll($select);

Open in new window

0
 

Author Closing Comment

by:sean-keys
ID: 31468618
Thanks!
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question