In this tutorial lets aim to create a simple webpage to display book list.

At first, create a Controller file – bookcontroller.php

 

<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

class Bookcontroller extends CI_Controller {

private function book_list(){

$book = Array();

$book[0]->name = “Hadoop In Action”;
$book[0]->quan = “10”;

$book[1]->name = “Hadoop Definitive Guide”;
$book[1]->quan = “20”;

$book[2]->name = “Hadoop Definitive Guide – 2”;
$book[2]->quan = “30”;

return $book;
}

public function index()
{

$books = $this->book_list();

$data[“books”] = $books;

$this->load->view(‘bookview’,$data);
}

}

 

 

Now, create a View file – bookview.php and add the following code.

 

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”utf-8″ />
<title>Book List</title>

</head>
<body>
<table align=”center” width =”200px”>
<tr>
<td> <h1> <u> Book List </u> </h1> </td>
</tr>
</table>

<table border=”2″ align=”center” width=400px”>
<tr>
<th height=”70px”> <u>
Items </u>
</th>
<th>
<u> Quantity </u>
</th>
</tr>

<?php
foreach($books as $book)
{
?>
<tr>
<p>
<td align=”center”> <h3><?php echo $book->name; ?></h3> </td>
<td align=”center”> <strong><?php echo $book->quan; ?></strong> </td>
</p>
<br />
</tr>
<?php
}
?>

<tr>

</tr>
</table>
</body>
</html>