2012-10-08 39 views
0

我正在使用數據表列出我的數據。它以與數據庫表中相同的順序顯示我的數據。但我想用不同的順序來展示它。 我的代碼:如何在zend框架中以不同的順序在數據庫中顯示數據?

$userData = array(); 
$row = array(); 
$action = array(); 
foreach ($students as $key => $student) { 
    foreach ($student as $key => $value) { 
     switch ($key) { 
      case 'firstName' : 
       $firstName = $value; 
       break; 

      case 'lastName' : 
       $lastName = $value; 
       $row[] = $lastName; 
       break; 

      case 'phone' : 
       $row[] = $value; 
       break; 

      case 'email' : 
       $row[] = $value; 
       break; 

      case 'studentId': 
       $row['DT_RowId'] = $value; 
       $action[] = "<a id = {$value} class = 'update'>Edit</a>&nbsp | &nbsp<a id = {$value} class = 'delete'>Delete</a> "; 
     } 
    } 
    $userData[] = array_merge($row, $action); 
    unset($row); 
    unset($action); 
} 

回答

1

我沒有得到確切,但如果你想在不同的順序列,我喜歡這樣 觀點: -

<?php foreach $zendDbRowObject->getTable()->getDisplayOrder() as $fieldName): ?> 
<?php echo $zendDbRowObject->$fieldName; ?> 
<?php endforeach; ?> 

controllar: -

public function getDisplayOrder() { 
// fake column names obviously... use yours here. 
return array(
    'column5', 
    'column1', 
    'column4', 
    'column2', 
    'column3' 
); 
} 
相關問題