0

I am using datatables to list my data. It showing my data in the same sequence as it is in database tables . But I want to show it in a different sequence. My code:

$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);
}
Raidri
  • 17,258
  • 9
  • 62
  • 65
user1559230
  • 2,790
  • 5
  • 26
  • 32

1 Answers1

1

I am not getting exactly but if you want column in different order, i do like this view:-

<?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'
 );
 }
Ammar Hayder Khan
  • 1,287
  • 4
  • 22
  • 49