显示来自2个表+ zend框架的数据

时间:2013-01-22 23:44:20

标签: php sql arrays zend-framework html-table

我想在html中将数据库中的数据显示到我的表中。 (当我点击链接时)

表“出生”字段:

  • year1999
  • year2000
  • year2001
  • year2002
  • year2003
  • YEAR2004
  • year2005
  • year2006
  • year2007
  • year2008
  • year2009

表“死亡”字段:

  • year1999
  • year2000
  • year2001
  • year2002
  • year2003
  • YEAR2004
  • year2005
  • year2006
  • year2007
  • year2008
  • year2009

我将从我的数据库获取数据真实的javascript中的ajax调用。我链接到我的indexcontroller中的一个动作。

Javascript代码:

$("#wijken ul li a").click(function(e){

        district = ($(this).text());

        loadTable(district);

      });

function loadTable(district){
    var param1 = district;

    $.ajax({ 
      url: 'index/getdata',         
      type: "POST",             
      data: {param1: param1},                        
      dataType: 'json',                
      success: function(result)          
      {
        var htmlContent = "";

       // HOW CAN I PARSE THE DATA?

        htmlContent += '</tbody></table>';
        $('#tabel').html(htmlContent);

      }, 
      error: function(request, status, error){
          alert(request.responseText);
      }
    });
}

我的IndexController:

public function getdataAction()
    {
        // DISABLE VIEW
        $this->view->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        // WIJK CLICKED
        $district = $this->_request->getParam('param1');

        // GET THE BIRTHS/YEAR
        $birthMapper = new Frontoffice_Model_BirthMapper();
        $array = $birthMapper->read($district);

        $this->_response->setBody(json_encode($array));
    }

我的BirthMapper:

public function read($wijk = null)
    {
        $table = $this->_dbTable;

        $columns = array('wijk'         => 'wijk',
                         'year1999'     => 'year1999',
                         'year2000'     => 'year2000',
                         'year2001'     => 'year2001',
                         'year2002'     => 'year2002',
                         'year2003'     => 'year2003',
                         'year2004'     => 'year2004',
                         'year2005'     => 'year2005',
                         'year2006'     => 'year2006',
                         'year2007'     => 'year2007',
                         'year2008'     => 'year2008',
                         'year2009'     => 'year2009',
        );

        $select = $table->select()
                        ->from($table,
                               $columns
                          )
                        ->where('wijk = :wijk')
                        ->bind(array(':wijk' => $wijk))

         ;

        if ($row = $table->fetchRow($select)) {
           return $row->toArray();
       }


        throw  new Exception('The requested Births cannot be found');
    }

现在我可以处理我的javascript中的1999年,2000年,2001年,2002年,2003年,2004年,2005年,2006年,2007年,2008年,2009年的字段.Yye1999。但是我如何为多个表执行此操作? (在javascript和控制器中)

0 个答案:

没有答案