Thursday, February 5, 2015

php codeigniter html pivot table example

IN CONTROLLER

<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class home extends HO_Site {

    public function __construct() {
        parent::__construct();
    }

    public function index() {
        $this->load->model('article_model');
        $where = array();
        $where['limit'] = 5;
        $where['offset'] = 0;
        $model = $this->article_model->get_list($where, null, array('id,title,createddate'));
        $this->view(array('data' => $model));
    }

}

IN VIEW

<?php
header('Content-Type: text/html; charset=utf-8');
echo 'processing...<br>';
print_r($data);
?>
<table style="border:1px solid #000;padding:5px;">
    <thead>
        <tr>
            <?php
            echo '<th>Талбар:</th>';
            for ($i = 0; $i < count($data); $i++) {
                echo '<th>Хэрэглэгч-' . $i . '</th>';
            }
            ?>
        </tr>
    </thead>
    <tbody>
        <?php
        $fieldNames = array_keys($data[0]);
        for ($i = 0; $i < count($fieldNames); $i++) {
            echo '<tr>';
            for ($j = 0; $j < count($data); $j++) {
                $item = $data[$j];
                if ($j == 0) {
                    echo '<th>' . $fieldNames[$i] . '</th>';
                }
                echo '<td>' . $item[$fieldNames[$i]] . '</td>';
            }
            echo '</tr>';
        }
        ?>
    </tbody>
</table>

RESULT





1 comment:

Teknik Servis said...

Please upload source codes this project.