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


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-20-2007, 09:07 AM
Junior Member
 
Join Date: Aug 2007
Posts: 6
Default need help for database selection

Hello,

this are my first steps with ZF, and I'm trying to build up a simple crm.
Now, I do need some help.

In a list (ContactController index action) I want to show:
name, surename, address_1

How can I realize this?

Dump of database:
PHP Code:
CREATE TABLE `adr_address` (
  `
idint(10unsigned NOT NULL auto_increment,
  `
adr_head_idint(10unsigned NOT NULL,
  `
titelvarchar(20collate latin1_general_ci default NULL,
  `
namevarchar(45collate latin1_general_ci default NULL,
  `
surenamevarchar(45collate latin1_general_ci default NULL,
  `
address_1varchar(45collate latin1_general_ci default NULL,
  `
countryvarchar(45collate latin1_general_ci default NULL,
  `
statevarchar(45collate latin1_general_ci default NULL,
  `
zipvarchar(20collate latin1_general_ci default NULL,
  `
cityvarchar(45collate latin1_general_ci default NULL,
  
PRIMARY KEY  (`id`)
ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=;

INSERT INTO `adr_addressVALUES (11'Herr''Mueller''Max''Teststr. 1'NULLNULLNULLNULLNULLNULL'99999''Testhausen');
INSERT INTO `adr_addressVALUES (21'Herr''Mueller''Max''Teststr. 2'NULLNULLNULLNULLNULLNULL'88888''Testhausen 2');
INSERT INTO `adr_addressVALUES (32'Frau''Meier''Lieschen''Kokusweg 999'NULLNULLNULLNULLNULLNULL'77777''Kokushausen');
INSERT INTO `adr_addressVALUES (42'Firma''Top Events'NULL'Teststr. 3'NULLNULLNULLNULLNULLNULL'55555''Testhausen 3');

CREATE TABLE `adr_head` (
  `
idint(10unsigned NOT NULL auto_increment,
  `
matchcodevarchar(45collate latin1_general_ci NOT NULL,
  
PRIMARY KEY  (`id`)
ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=;

INSERT INTO `adr_headVALUES (1'Mueller, Max');
INSERT INTO `adr_headVALUES (2'Meier, Lieschen');

CREATE TABLE `adr_login` (
  `
idint(10unsigned NOT NULL auto_increment,
  `
adr_head_idint(10unsigned NOT NULL,
  `
namevarchar(20collate latin1_general_ci NOT NULL,
  `
pwdvarchar(45collate latin1_general_ci NOT NULL,
  
PRIMARY KEY  (`id`)
ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=;

INSERT INTO `adr_loginVALUES (11'admin''admin'); 

content of Controller crm/application/controllers/ContactController.php
PHP Code:
<?php

class ContactController extends Zend_Controller_Action 
{
    function 
init()
    {
        
$this->initView();
        
Zend_Loader::loadClass('Contact');
        
$this->view->baseUrl $this->_request->getBaseUrl();
        
$this->view->user Zend_Auth::getInstance()->getIdentity();
    }

    
    function 
preDispatch()
    {
        ...
    }

    function 
indexAction()
    {
        
$this->view->title "Kontakte";
        
        
$contact = new Contact();
        
$this->view->contacts $contact->fetchAll();        
        
$this->render();
        
    }  
    
    function 
detailAction()
    {
        ...      
    }
    
    function 
addAction()
    {
        ...
    }
    
    function 
editAction()
    {
        ...
    }
    
    function 
deleteAction()
    {
        ...
    }
}

content of crm/application/models/Contact.php
PHP Code:
<?php

class Contact extends Zend_Db_Table
{
    protected 
$_name 'adr_head';
}
content of crm/application/views/scripts/contact/index.phtml:
PHP Code:
<?php echo $this->render('header.phtml'); ?>
<h1><?php echo $this->escape($this->title); ?></h1>
<p><a href="<?php echo $this->baseUrl ?>/contact/add">new Contact</a></p>
<table>
<tr>
    <th width="30" align="left">ID</th>
    <th width="130" align="left">Matchcode</th>
    <th width="80">Name</th>
    <th width="80">Surename</th>
    <th width="100">Street</th>
    <th>&nbsp;</th>
</tr>

<?php foreach($this->contacts as $contact) : ?>
<tr>
    <td align="left"><?php echo $this->escape($contact->id);?></td>
    <td align="left"><?php echo $this->escape($contact->matchcode);?></td>
    <td>adr_address.name:</td>
    <td>adr_address.surname:</td>
    <td>adr_address.address_1:</td>
    <td>
        <a href="<?php echo $this->baseUrl ?>/contact/detail/id/<?php echo $contact->id;?>">details</a>
        <a href="<?php echo $this->baseUrl ?>/contact/edit/id/<?php echo $contact->id;?>">change</a>
        <a href="<?php echo $this->baseUrl ?>/contact/delete/id/<?php echo $contact->id;?>">delete</a>
    </td>
</tr>
<?php endforeach; ?>
</table>
<?php echo $this->render('footer.phtml'); ?>

Thanks for help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-20-2007, 10:05 AM
Junior Member
 
Join Date: Aug 2007
Posts: 6
Default

Sorry, I think that my question wasn't clear anough.

The SQL command, I want to build into the code is:

SELECT adr_head.id, adr_head.matchcode, adr_address.titel, adr_address.name, adr_address.surename, adr_address.address_1
FROM (adr_head
LEFT JOIN adr_address ON adr_address.adr_head_id=adr_head.id)

How can I do this?
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 09:22 PM.