?
Solved

SELECT statement in Zend_Framework

Posted on 2008-06-18
2
Medium Priority
?
369 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

741 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