Seach

Showing posts with label codeigniter. Show all posts
Showing posts with label codeigniter. Show all posts

remove index.php in codeignitor and routing

we need to add a small .htaccess script in the root folder of the codeignitor 

.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

if you want to remove the codeignitor  contoller from the url the we need to go to applicatio folder then the config folder route.php here add $route['about']='Front/about';
here front is the controller and the about is the function name
htaccess remove the usage of index.php and route remove the full usage of front/about 
now we can access the page by about/inde page

pagination example in codeigniter

view page

<div id="item">
LIST
</div>
<table >
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
<th>Stock</th>
<th>Image</th>
<th>Action</th>
<?php
if(isset($result))
{
foreach ($result as $data)
{
?>
<tr>
<td>
    <input type="text" name="name" value="<?php echo $data['name'];?>">
</td>
<td>
    <input type="text" name="qty" value="<?php echo $data['qty'];?>" style="width: 40px;">

</td>
<td>
    <input type="text" name="price" value="<?php echo $data['price'];?>" style="width: 80px;">
</td>
<td>
        <input type="text" name="price" value="<?php echo $data['stock'];?>" style="width: 40px;">


</td>
<td>
    <img src="<?php echo base_url().''.$data['image'];?>" width="70" height="100" title="Picture cannot be changed">
</td>
<td>
    <a href="<?php echo $data['id'];?>" id="edit"  ><img src="http://localhost/backery/assets/images/edit.jpg" height="20" width="20"></a>
    &nbsp;&nbsp;
    <a href="<?php echo $data['id'];?>" id="delete"  ><img src="http://localhost/backery/assets/images/delete.jpg" height="20" width="20"></a>
   
</td>
</tr>
<?php
}} ?>
</table>
<div id="link">
<?php echo $link;?>
</div>

controller

public function home()
{
$this->session_alive();
$total=$this->admin_model->count();
$config['total_rows']=$total;
$config['per_page']=2;
$config['base_url']=  site_url().'/admin/home/';
$data['result']=$this->admin_model->list_items(2,$this->uri->segment(3));
if(count($data)>=1)
{
$this->pagination->initialize($config);
$data['link']=$this->pagination->create_links();

$this->load->view('home',$data);
}
else
{
$this->load->view('home');
}
}

model

//used to paginate products
public function list_items($limit,$segment)
{
    $query=$this->db->get('product',$limit,$segment);
    return $query->result_array();
}
//used to find the total
public function count()
{
    return $this->db->count_all('product');
}

how to create a global variable that can be accessed in any view page in codeigniter

1)create a class in application/library folder
2)create a php file to set data to library
3)in autoload.php call the library

Globals.php//in application/library
<?php
class Globals {

// Pass array as an argument to constructor function
public function __construct($config = array()) {

// Create associative array from the passed array
foreach ($config as $key => $value) {
$data[$key] = $value;
}

// Make instance of CodeIgniter to use its resources
$CI = & get_instance();

// Load data into CodeIgniter
$CI->load->vars($data);
}

}

?>

Globals.php// in application/config /

$config['name']='hithin';

demo.php//controller
<?php
defined('BASEPATH') OR EXIT('Dirrect access not allowed');
class Demo extends CI_Controller
{
    public function __construct() {
        parent::__construct();
       
    }
    public function index()
    {
        $this->load->view('demo_view');
    }
}

demo_view.php //view
<?php
echo $name;

simple money payment using paypal api using codeigniter

create a paypal account
 we use paypal.com to original sits for development purpose we use sandbox.paypal account for testing
for reference  of integrating paypal reffer developer.paypal.com documentation and dashbord

controller

<?php
defined('BASEPATH') OR EXIT('Dirrect access not allowed');
class Pay extends CI_Controller
{
    public function __construct() {
        parent::__construct();
    }
    public function index()
    {
        $data['settings']=array('id'=>'your sandboxpaypal id  //mine is sellerhithn@gmail.com','url'=>'https://www.sandbox.paypal.com/cgi-bin/webscr');//test url  for testing provided by paypal orignal is http://www.paypal.com
        $this->load->view('pay_view',$data);
    }
    public function success()
    {
        $this->load->view('success_view');
       
       
    }
    public function failer()
    {
        echo 'problem occured';
    }
}

view
 //to know more options  visit https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/formbasics/
 
 <form method="post" action="<?php echo $settings['url'];?>">
    <input type='hidden' name='cmd' value='_xclick'>
    <input type="hidden" name="address_override" value="1">
    <input type="hidden" name="first_name" value="hithin chandran">


    <input type="hidden" name="business" value="<?php echo $settings['id'];?>">
    <input type='hidden' name='item_name' value='Exam fee'>
    <input type='hidden' name='item_name' value='<?php echo rand(1,10000);?>'>
    <input type='hidden' name='amount' value='1000'>
    <input type='hidden' name='no_shipping' value='1'>
    <input type='hidden' name='currency_code' value='USD'>
    <input type='hidden' name='handling' value='0'>
    <input type='hidden' name='cancel_return' value="<?php echo site_url('pay/failer'); ?>">
    <input type='hidden' name='return' value="<?php echo site_url('pay/success'); ?>">

    <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">

                   
</form>
<div>
  
</div>


how to populate a dropdown list in codeigniter using json,jquery,ajax

view

<head>
    <script src="<?php echo base_url().'js/jquery.js';?>"></script>
</head>
<form method="post" >
    <select id="select">
        
    </select>
</form>

<script>
   $(document).ready(function(e){
       $.ajax({
           dataType: 'json',
           url: "json_",
           type: 'POST',
           processData: false,
           cache: false,error: function (jqXHR, textStatus, errorThrown) {
                        alert('error occured');
                    },
           success: function (data, textStatus, jqXHR)
           {
    
//           $.each(data,function(key, value){
//             $('<option />', {value: value
//                         .actor_id, text: value.first_name}).appendTo("#select");
//        });
    
$.each(data,function(key,value)
{
    $('</option>',{value:value.actor_id,text:value.first_name}).appendTo("#select");
});}            
       });
   });
</script>

controller
public function json_()
    {
        $this->load->model('json_model');
        $tmp=$this->json_model->fetch();
        echo json_encode($tmp);
        
    }

model

public function fetch()
    {
        $this->db->select('actor_id,first_name');
        $this->db->from('actor');
        $data=$this->db->get();
        return $data->result_array();
    }




how to use session class in codeigniter login demo

Controller emp.php

<?php
defined('BASEPATH') OR EXIT('Dirrect Access Not Allowed');
class Emp extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->library('session'); //used to load session library
        $this->load->helper('url','form');
    }
    public function index()
    {
        $this->load->view('login');
    }
    public function login()
    {
     $data=array('email'=>$this->input->post('userid'),'password'=>$this->input->post('password'));
     $this->load->model('login_user');
     $record=$this->login_user->entry($data);
     $this->session->set_userdata(array('id'=>$record->id,'email'=>$record->email));
     $this->load->view('userdata');
    }
}

Model login_user.php

<?php
defined('BASEPATH') OR EXIT('Dirrect Script Not Allowed');
class Login_user extends CI_Model
{
    public function __construct() {
        parent::__construct();
        $this->load->database();//used to load db settings and initialize database
    }
    public function entry($data)
    {
        $this->db->select("*");
        $this->db->from('login');
        $this->db->where($data);
        $query=$this->db->get();
        return $query->row();//returns a single row of record as object array
    }
}

login.php

<form method="post" action="<?php echo site_url('emp/login'); ?>">
    <table border="1">
        <tr>
            <td><label>UserId</label></td>
            <td><input type="text" name="userid" ></td>
        </tr>
        <tr>
            <td><label>Password</label></td>
            <td><input type="text" name="password" ></td>
        </tr>
        <tr>
            <td>
                <input type="submit" name="login" value="Login">
            </td>
        </tr>
    </table>

</form>

userdata.php

<?php
echo $this->session->userdata('id');
echo "<br/>";
echo $this->session->userdata('email');


multiple table join in codeigniter

viewpage(employee_data_edit_view)

<form method="post">
    <table border='1'>
        <tr>
            <td><label>Name</label></td>
            <td><input type="text" name="name" value="<?php echo $result->name;?>"></td>
        </tr>
       
         <tr>
            <td><label>Age</label></td>
            <td><input type="text" name="age" value="<?php echo $result->age;?>"></td>
        </tr>
         <tr>
            <td><label>Gender</label></td>
            <td><input type="text" name="gender" value="<?php echo $result->gender;?>"></td>
        </tr>
       
         <tr>
            <td><label>Email</label></td>
            <td><input type="text" name="emailid" value="<?php echo $result->emailid;?>"></td>
        </tr>
       
        <tr>
            <td><label>Panno</label></td>
            <td><input type="text" name="panno" value="<?php echo $result->panno;?>"></td>
        </tr>
       
        <tr>
            <td><label>Phone</label></td>
            <td><input type="text" name="phone" value="<?php echo $result->phone;?>"></td>
        </tr>
       
         <tr>
            <td><label>Address</label></td>
            <td><input type="text" name="address" value="<?php echo $result->address;?>"></td>
        </tr>
       
         <tr>
            <td><label>UserId</label></td>
            <td><input type="text" name="userid" value="<?php echo $result->userid;?>"></td>
        </tr>
         <tr>
            <td><label>Password</label></td>
            <td><input type="text" name="password" ></td>
        </tr>
    </table>
</form>

Controller(employee)
i only providing the function inside the Employee controller class
 public function empdataview($id)
    {
        $this->load->model('employee_model');
    $data=array('empcode'=>$id);
     $query['result']=$this->employee_model->employee_data($data);
    $this->load->view('employee_data_edit_view',$query);
    }
 

Model(employee_model)

public function employee_data($data)
{
     
    $this->db->select(
    'user_info.name,user_info.age,user_info.gender,user_info.panno,user_info.image,user.emailid,user.phone,user.address,userlogin.userid,userlogin.password');
    $this->db->from('user_info');
    $this->db->join('user','user.empcode=user_info.empcode');
    $this->db->join('userlogin','userlogin.empcode=user.empcode');
    $this->db->where('userlogin.empcode',$data['empcode']);
    $query=$this->db->get();
    return $query->row();
}










delete update using jquery in codeigniter

note create a js in codeigniter foler and add jquery to it
create a database database
load url,form_validation,form to auto load.php
set database.php

Form.php(Controller)

<?php
defined('BASEPATH') OR EXIT('Dirrect Access Not Allowed');
class Form_model extends CI_Model
{
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }
    public function add($data)
    {
     return  $this->db->insert('exp_registeration',$data);
     
       
    }
    public function show()
    {
        $query=$this->db->query("SELECT * FROM  exp_registeration");
        return $query->result();
    }
    public function remove($id)
    {
       $this->db->wehre('id',$id);
       $this->db->delete("exp_registeration");
    }
    public function update($data)
    {
        $update_data=array('name'=>$data[0],'age'=>$data[1],'emailid'=>$data[2],'phoneno'=>$data[3],'address'=>$data[4]);
$this->db->where('id',$data[5]);
$this->db->update("exp_registeration",$update_data);
    }
   }?>


form_view.php(view file)

<link href="<?php echo base_url()."/css/style.css"; ?>" rel="stylesheet">
<form method="post" action="<?php echo site_url('Form/insert'); ?>">
    <table border="1" id="table_form">
        <tr>
            <td>
                <label>Name</label>
            </td>
            <td>
                <input type="text" name="student_name" value="<?php echo set_value('student_name');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Age</label>
            </td>
            <td>
                <input type="text" name="age" value="<?php echo set_value('age');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Email id</label>
            </td>
            <td>
                <input type="text" name="email_id" value="<?php echo set_value('email_id');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Phone Number</label>
            </td>
            <td>
                <input type="text" name="phone_number" value="<?php echo set_value('phone_number');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Address</label>
            </td>
            <td>
                <input type="text" name="address"value="<?php echo set_value('address');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Password</label>
            </td>
            <td>
                <input type="text" name="password" value="<?php echo set_value('password');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Retype Password</label>
            </td>
            <td>
                <input type="text" name="rpassword" value="<?php echo set_value('rpassword');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <input type="submit" name="save" value="Save">
            </td>
            <td>
                <input type="submit" name="show" value="Show">
            </td>
        </tr>
    </table>

</form>
<?php
echo validation_errors();
?>
<?php
if(isset($_REQUEST['show']))
{
    redirect('Form/show');
}
?>


Display_student_data.php(view)

<header>
<!--    <script src="../../js/jquery.js" type="text/javascript"></script>-->
    <script src="<?php echo base_url()."js/jquery.js"?>"></script>
</header>
<form method="post" id="form1">
   
   
    <table border="1">
        <th>Name</th>
        <th>Age</th>
        <th>Email</th>
        <th>Phone NO</th>
        <th>Address</th>
        <th>Operation</th>
<?php
$i=1;
foreach ($result as $data)
{
 
 ?>
        <tr>
            <td><input type="text" name="name" value="<?php echo $data->name;?>" id=<?php echo "name".$i;?>></td>
            <td><input type="text" name="name" value="<?php echo $data->age;?>" id=<?php echo "age".$i;?>></td>
            <td><input type="text" name="name" value="<?php echo $data->emailid;?>" id=<?php echo "email".$i;?>></td>
            <td><input type="text" name="name" value="<?php echo $data->phoneno;?>" id="<?php echo "phone".$i;?>"></td>
            <td><input type="text" name="name" value="<?php echo $data->address;?>" id="<?php echo "address".$i;?>"></td>
            <td><a href="<?php echo site_url()."/Form/edit/".$data->id; ?>" id="edit<?php echo $i;?>">Edit</a>&nbsp;&nbsp;&nbsp;<a href="<?php echo site_url()."/Form/delete/".$data->id;?>" id="delete">Delete</a></td>
        </tr>      
<?php
$i++;
}
?>
    </table>
</form>
<script>
    $(document).ready(function(e)   
    {
      
    limit=<?php echo $i-1;?>;
   
       $('a').click(function(e){
    choice=this.id.substr(0,this.id.length-1);
   
           id_=this.id.slice(-1);
           entryno=this.href.slice(-1);
          
           e.preventDefault();
           if(choice=="edit")
           {
           name=$("#name"+id_).val();
           age=$("#age"+id_).val();
           email=$("#email"+id_).val();
           phone=$("#phone"+id_).val();
           address=$("#address"+id_).val();
           data=name+"/"+age+"/"+email+"/"+phone+"/"+address+"/"+entryno;
           $.ajax({
                    url:'edit',
                    type:'post',
                    processData: false,
                    data:'data='+data,
                    success: function (data, textStatus, jqXHR) {
                        alert('Edited');
                    },
                 
                    });
                }
                else
                {
                   $.ajax({
                       url:'delete',
                       type:'post',
                       processData: false,
                       data:'id='+entryno,
                   });
                }
    });
   
    });
</script>

Form_model.php(model)

<?php
defined('BASEPATH') OR EXIT('Dirrect Access Not Allowed');
class Form_model extends CI_Model
{
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }
    public function add($data)
    {
     return  $this->db->insert('exp_registeration',$data);
     
       
    }
    public function show()
    {
        $query=$this->db->query("SELECT * FROM  exp_registeration");
        return $query->result();
    }
    public function remove($id)
    {
       $this->db->wehre('id',$id);
       $this->db->delete("exp_registeration");
    }
    public function update($data)
    {
        $update_data=array('name'=>$data[0],'age'=>$data[1],'emailid'=>$data[2],'phoneno'=>$data[3],'address'=>$data[4]);
$this->db->where('id',$data[5]);
$this->db->update("exp_registeration",$update_data);
    }
   
   
}


?>

table structure

-- phpMyAdmin SQL Dump
-- version 3.5.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jul 02, 2015 at 03:50 PM
-- Server version: 5.5.24-log
-- PHP Version: 5.3.13

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `database`
--

-- --------------------------------------------------------

--
-- Table structure for table `exp_registeration`
--

CREATE TABLE IF NOT EXISTS `exp_registeration` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  `age` int(11) NOT NULL,
  `emailid` varchar(300) NOT NULL,
  `phoneno` int(11) NOT NULL,
  `address` varchar(300) NOT NULL,
  `password` varchar(400) NOT NULL,
  PRIMARY KEY (`emailid`),
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

--
-- Dumping data for table `exp_registeration`
--

INSERT INTO `exp_registeration` (`id`, `name`, `age`, `emailid`, `phoneno`, `address`, `password`) VALUES
(2, 'hithin', 25, 'hh@gmail.com', 2147483647, 'ekn njarakal', 'c8383b5122dfc6cbf715d84167656d39'),
(3, 'abcf', 25, 'hhiitthhiinn@gmail.com', 2147483647, 'kerela ernakulam njarakal', 'e2fc714c4727ee9395f324cd2e7f331f');

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;









file upload in codeigniter

fileupload.php (controller)


<?php
defined('BASEPATH') OR EXIT('Dirrect Access Not Allowed');
class Fileupload extends CI_Controller
{
    public function __construct() {
        parent::__construct();
      
    }
    public function index()
    {
        $this->load->view('fileupload_view',array('error'=>''));
      
    }
  
    public function upload()
    {
        $config['allowed_types']='jpg|pdf|png';//setting allowed extensions
        $config['upload_path']='./assets/'; //path
        $this->load->library('upload',$config); //loading library upload and set upload settings
       
        if($this->upload->do_upload('upload'))
        {
           $data=  array('result'=>$this->upload->data());
           $this->load->view('fileupload_result_view',$data);
        }
 else {
            $this->load->view('fileupload_view',array('error'=>$this->upload->display_errors()));
 }
    }
}
?>
fileupload_view.php(view)


<form method="post" enctype="multipart/form-data" action="<?php echo site_url('fileupload/upload');?>">
    <table border="1">
        <tr>
            <td>
                <label>File Name</label>
            </td>
            <td>
                <input type="file" name="upload">
            </td>
        </tr>
        <tr>
            <td>
                <input type="submit" name="save" value="Save">
            </td>
        </tr>
    </table>
</form>
<?php echo $error;?>


fileupload_result_view.php(view)


<?php
foreach ($result as $key=>$data)
{
    echo "<br/>".$key.="".$data;
}
?>



form validation in codeigniter

set libarary form_validation in autoload.php




validation.php


<?php
defined('BASEPATH') OR EXIT('Dirrect script not allowed');
class Validation extends CI_Controller
{
   
function __construct() {
    parent::__construct();
}  
public function index()
{
    $this->load->view('Validation_view');
}
public function validate()
{
    $this->form_validation->set_rules('name','User Name','required',array('required'=>'please enter a user name'));
    $this->form_validation->set_rules('age','Age ','required|numeric');
    $this->form_validation->set_rules('email','Email','required|valid_email');
    $this->form_validation->set_rules('phoneno','Phone number','required|numeric|max_length[10]');
    $this->form_validation->set_rules('password','password','trim|md5|required');
    $this->form_validation->set_rules('rpassword','password','md5|trim|required|matches[password]');
    if($this->form_validation->run()==FALSE)
    {
        $this->load->view("validation_view");
    }
 else {
        echo 'no error';
    }
}
}
?>


validation_view.php


<?php echo validation_errors();?>
<form method="post" action="<?php echo site_url('validation/validate')?>">
    <table border="1">
        <caption><h1>Registeration</h1></caption>
        <tr>
            <td>
                <label>Name</label>
            </td>
            <td>
                <input type="text" name="name" value="<?php echo set_value('name'); ?>">
            </td>
        </tr>
        <tr>
            <td>
                <label>Age</label>
            </td>
            <td>
                <input type="text" name="age" value="<?php echo set_value('age');?>">
            </td>
        </tr>
       
         <tr>
            <td>
                <label>Email</label>
            </td>
            <td>
                <input type="text" name="email" value="<?php echo set_value('email');?>">
            </td>
        </tr>
        <tr>
            <td>
                <label>Phone No</label>
            </td>
            <td>
                <input type="text" name="phoneno" value="<?php echo set_value('phoneno');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Password</label>
            </td>
            <td>
                <input type="text" name="password" value="<?php echo set_value('password');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Retype Password</label>
            </td>
            <td>
                <input type="text" name="rpassword" value="<?php echo set_value('rpassword');?>">
            </td>
        </tr>
       
       
        <tr>
            <td>
                <input type="submit" name="save" value="Save">
            </td>
        </tr>
       
    </table>
</form>







simple login example in codeigniter

set
$autoload['libraries'] = array('database'); ,$autoload['helper'] = array('url','form');
set database.php database entries like hostname,user,password,databasename
create a controller entry.php


<?php
defined("BASEPATH") OR exit("Dirret Sript Not Allowed");
class Entry extends CI_Controller
{
  function __construct()
  {
      parent::__construct();
  } 
  public function index()
  {
      $this->load->view("entryview");
  }
  public function login()
  {
      $this->load->model("entrymodel");
      $status=$this->entrymodel->validate();
     
      if($status==1)
      {
          redirect("member");
      }
      else
      {
          echo "invalid user";
      }  
  }
   public function signin()
   {
       $this->load->view("create_new_user");
      
   }
   public function register()
   {
       $this->load->model("create_new_user_model","obj");
       $status=$this->obj->create();
       if($status)
       {
           redirect("entry");
       }
   }
}


?>


create  a model entrymodel.php


<?php
defined("BASEPATH") OR exit("Dirrect Access Not Allowed");
class Entrymodel extends CI_Model
{
   
    function __construct() {
        parent::__construct();
    }
   
    public function validate()
    {
        $this->db->where('email',  $this->input->post('emailid'));
        $this->db->where('password',  $this->input->post('password'));
        $query=$this->db->get('login');
        return $query->num_rows();
    } 
}
?>


create a view page create_new_user.php


<form method="post"  action="<?php echo site_url("entry/login")?>" >
      <table border="1">
          <tr>
              <td>
                  <label>UserId</label>
              </td>
              <td>
                  <input type="text" name="emailid">
                 
              </td>
          </tr>
          <tr>
              <td>
                  <label>
                      Password
                  </label>
              </td>
              <td>
                  <input type="text" name="password">
                 
              </td>
             
          </tr>
          <tr>
              <td>
                  <input type="submit" name="submit" value="Login">
              </td>
              <td>
                  <a href="<?php echo base_url(); ?>index.php/entry/signin">Register</a>
                 
              </td>
          </tr>
    </table>
 
 
 







how to retrive data from database using codeigniter 3

Blog_view.php

<html>
<body><form method="post">
<table border="1">
<th>Serial Number</th>
<th>Name</th>
<?php
foreach($query as $result)
{?>
<tr>
<td>
<?php echo $result['id'];?>
</td>
<td>
<?php echo $result['name'];?>
</td>
</tr>    
<?php   
}
?>
</table>
</form>
</body>
</html>



how to retrive data from database using codeigniter 2

Blog_view.php
<?php

class Blog_model extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }
   
public function getall()
{
    $this->load->database();//used to load database
$query=$this->db->get('student_details');//used to fetch data from student_details
return $query->result_array();//used to return the result
   
}
}
?>


how to retrive data from database using codeigniter 1

1)download and extract codeigniter to wamp folder
2)open application/config/database.php then change the following
$db['default']['hostname'] = 'your hostname';
$db['default']['username'] = ''your mysql user name";
$db['default']['password'] = ''your mysql password";
$db['default']['database'] = 'your database name';
3)open config folder under that config.php then add
$config['index_page'] = 'index.php'; //this is the page loaded when you press the folder
4)create 3 files under controller,model.view
under controller create Blog.php,under model Blog_model.php,under view create
Blog_view.php

Blog.php

<?php
class Blog extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('Blog_model');//used to load the model class
       
    }
   
    public function index()
    {
        $data['query']=$this->Blog_model->getall();//used to call model function
       
if(count($data)>0)
      
        {
                $this->load->view('Blog_view',$data);//used to call view class
       
        }
        else
        {
            echo 'nothing to show';
            exit();
        }
    }
   
}

?>