Create a controller file named test.php in the application/classes/controller folder and type the following code:
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Test extends Controller_Template {
public function action_database()
{
$p = DB::select()->from('posts')->execute();
echo View::factory('database')->bind('data',$p);
}
}
Now we need to create a view file named database.php in the views folder. So, create the database.php file and paste the following code:
<!DOCTYPE html>
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-7s5uDGW3AHqw6xtJmNNtr+OBRJUlgkNJEo78P4b0yRw= sha512-nNo+yCHEyn0smMxSswnf/OnX6/KwJuZTlNZBjauKhTK0c+zT+q5JOCx0UFhXQ6rJR9jg6Es8gPuD2uZcYDLqSw==" crossorigin="anonymous">
<!-- <link href='https://fonts.googleapis.com/css?family=Roboto|Oswald' rel='stylesheet' type='text/css'> -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
<title><?php echo 'title' ;?></title>
<style type="text/css">
body{
background-color: #eee;
}
</style>
</head>
<body>
<div class="container">
<h2> Table Explorer </h2>
<h4>Pass me all data from a table and I shall show you all fields and its value.</h4>
<code>for example, following code was used in a Controller and then data passed to me:
<br>
$allUsers = DB::select()->from('users')->execute();
<br>
$this->response->body(View::factory('users')->bind('data',$allUsers));
</code>
<table id="mt" class="table table-responsive table-striped">
<?php
$i = 0;
$firstRow=$data[0];
?>
<thead>
<?php
foreach($firstRow as $key => $value):
echo "<th>". $key . "</th>";
endforeach;
?>
</thead>
<?php
foreach($data as $point):
echo "<tr>";
foreach($point as $key => $value):
echo "<td>". $value . "</td>";
endforeach ;
echo "</tr>";
endforeach ; ?>
</table>
</div>
</body>
<style type="text/css">
table{
margin-top: 5%;
background-color: #ddd;
border-radius:2px;
}
</style>
<script>
$(document).ready(function(){
$('#mt').DataTable();
// alert('Google');
});
</script>
</html>
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Test extends Controller_Template {
{
$p = DB::select()->from('posts')->execute();
echo View::factory('database')->bind('data',$p);
}
}
Now we need to create a view file named database.php in the views folder. So, create the database.php file and paste the following code:
<!DOCTYPE html>
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-7s5uDGW3AHqw6xtJmNNtr+OBRJUlgkNJEo78P4b0yRw= sha512-nNo+yCHEyn0smMxSswnf/OnX6/KwJuZTlNZBjauKhTK0c+zT+q5JOCx0UFhXQ6rJR9jg6Es8gPuD2uZcYDLqSw==" crossorigin="anonymous">
<!-- <link href='https://fonts.googleapis.com/css?family=Roboto|Oswald' rel='stylesheet' type='text/css'> -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
<title><?php echo 'title' ;?></title>
<style type="text/css">
body{
background-color: #eee;
}
</style>
</head>
<body>
<div class="container">
<h2> Table Explorer </h2>
<h4>Pass me all data from a table and I shall show you all fields and its value.</h4>
<code>for example, following code was used in a Controller and then data passed to me:
<br>
$allUsers = DB::select()->from('users')->execute();
<br>
$this->response->body(View::factory('users')->bind('data',$allUsers));
</code>
<table id="mt" class="table table-responsive table-striped">
<?php
$i = 0;
$firstRow=$data[0];
?>
<thead>
<?php
foreach($firstRow as $key => $value):
echo "<th>". $key . "</th>";
endforeach;
?>
</thead>
<?php
foreach($data as $point):
echo "<tr>";
foreach($point as $key => $value):
echo "<td>". $value . "</td>";
endforeach ;
echo "</tr>";
endforeach ; ?>
</table>
</div>
</body>
<style type="text/css">
table{
margin-top: 5%;
background-color: #ddd;
border-radius:2px;
}
</style>
<script>
$(document).ready(function(){
$('#mt').DataTable();
// alert('Google');
});
</script>
</html>
No comments:
Post a Comment