phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


CodeIgniter - Form: Creating Table List Without Table Library

Tag: CodeIgniter, framework, MVC, database, table, list   Category: PHP Framework
post: 28 Feb 2008 read: 2,848


CodeIgniter Form Step By Step Tutorial - Part 14: We have learned create table use table library at here. In this post, we try to create as manual (not use table library).

First, add a method books_getall() at model (books_model.php) like this:


  function books_getall()
  {
    $this->load->database();
    $query = $this->db->get('books');
    return $query->result();
  } 

Update controller (books.php), like this:


  function main(){
    $this->load->library('table');
	$this->load->helper('html');	
	$this->load->model('books_model');
	
	$data = $this->books_model->general();
	$data['query'] = $this->books_model->books_getall();
		
	$this->load->view('books_main',$data);
  }

Last, update views (books_main.php) like this:


<html>
<head>
<link rel="stylesheet" type="text/css" 
      href="<?php echo "$base/$css"?>">
</head>
<body>
<div id="header">
<? $this->load->view('books_header'); ?>
</div>
<div id="menu">
<? 	$this->load->view('books_menu'); ?>
</div>
<? echo heading('List of Books',3); ?>
<table border="1">
  <tr>
    <th>ID</th>
    <th>Title</th>    
    <th>Author</th>    
    <th>Year</th>    
  </tr>
<?php 
foreach($query as $row){
  echo "<tr>";
	echo "<td>". $row->id ."</td>";
	echo "<td>". $row->title ."</td>";
	echo "<td>". $row->author ."</td>";
	echo "<td>". $row->year ."</td>";
  echo "</tr>";	
}
?>
</table>

<div id="footer">
<? $this->load->view('books_footer'); ?>
</div>

</body>
</html>

Result like this:

codeigniter form create table


Series this article:
CodeIgniter - Form: Creating Skeleton
CodeIgniter - Form: File Structure
CodeIgniter - Form: Creating Layout Code
CodeIgniter - Form: Creating Menu Library
CodeIgniter - Form: Putting Text at Header and Footer
CodeIgniter - Form: Centralizing $data
CodeIgniter - Form: Adding CSS
CodeIgniter - Form: Creating Form HTML
CodeIgniter - Form: Creating Beautiful Form Code
CodeIgniter - Form: CodeIgniter HTML Style
CodeIgniter - Form: Preparing Table at Database
CodeIgniter - Form: Creating Insert Data
CodeIgniter - Form: Creating List Data Use Table Library
CodeIgniter - Form: Creating Table List Without Table Library
CodeIgniter - Form: Using URL Helper
CodeIgniter - Form: Showing Single Data for Form Edit
CodeIgniter - Form: Something Happen With Form Parameters
CodeIgniter - Form: Updating Data
CodeIgniter - Form: Deleting Data

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Joomla: Fast Road to Understand Component Programming
Chart: How to Build Cool Animation Real Time Chart
Email: Send Attachement Mail
SMS : Sending SMS with PHP and ActiveXperts (Part 1)

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


624
posting