0

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

表“出生”字段:

  • 1999年
  • 2000年
  • 2001年
  • 2002年
  • 2003年
  • 2004年
  • 2005年
  • 2006年
  • 2007年
  • 2008年
  • 2009年

表“死亡”字段:

  • 1999年
  • 2000年
  • 2001年
  • 2002年
  • 2003年
  • 2004年
  • 2005年
  • 2006年
  • 2007年
  • 2008年
  • 2009年

我将从我的数据库中获取数据,真正的 ajax 调用在 javascript 中。我链接到我的 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);
      }
    });
}

我的索引控制器:

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));
    }

我的出生地图:

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 年字段作为result.year1999 处理。但是我怎样才能为多个表做到这一点?(在 javascript 和控制器中)

4

0 回答 0