0

我正在使用数据表来列出我的数据。它以与数据库表中相同的顺序显示我的数据。但我想以不同的顺序展示它。我的代码:

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

1 回答 1

1

我没有得到确切的信息,但是如果您希望列以不同的顺序,我确实喜欢这种观点:-

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

控制器:-

public function getDisplayOrder() {
// fake column names obviously... use yours here.
 return array(
  'column5',
  'column1',
  'column4',
  'column2',
  'column3'
 );
 }
于 2012-10-08T10:31:01.437 回答