How to get a list of data in codeigniter using php

In this tutorial learn how to get a list of data in codeigniter using php, Its easy to get data list from view to controller,  Create a Signup.php in controller  keep first letter capital and create a file signup.php in view now  same get list for create a User.php in controller and user.php in view

Controller

application/controller/Signup.php


<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Signup extends CI_Controller {

public function index()
{

//controller part to get value and insert into the database

    $message="";
 
    if(isset($_POST['btnsignup'])){
        //value get
        $name=$this->input->post('name');
        $email=$this->input->post('email');
        $pass=$this->input->post('password');
        $address=$this->input->post('address');

  //here insert the data before we need to connect the data

  // now also load the database file
 $insdata=array('name'=>$name,'email'=>$email,'pass'=>$pass,'address'=>$address);    

        $this->db->insert('login',$insdata);

 $message="Thank You successfully registered";
   
      }

$data['message']=$message;

$this->load->view('pages/signup',$data);
 
}
}

application/view/pages/signup.php

<html>
<head>
<title>Sign up</title>
<style type="text/css">
input{
font-family: "Helvetica","Arial",sans-serif;
    margin: 0;
    padding: 4px 0;
    width: 207px;
    background: 0 0;
    text-align: left;
    }
#submit{
background-color: skyblue;
text-align: center;

}  

<?-- view signup data of form detail -->  
</style>
</head>
<body>
<div style="text-align:center;margin-top: 8%;">
<h1> Sign up</h1>
<div style="color:green">
<?php echo $message; ?>  <br/><br/>
</div>
<form action="" method="post">

<input type="text" name="name" value="name" /><br/><br/>
<input type="email" name="email" value="email" /><br/><br/>
<input type="password" name="password" value="password" /><br/><br/>
<input type="address" name="address" value="address" /><br/><br/>
<input type="submit" name="btnsignup" id="submit" value="submit" />
</form>
</div>
</body>
</html>


Controller

application/controller/User.php

User.php

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class User extends CI_Controller {

public function index()
{

//pages to call

$this->load->view('pages/user');

   }
 
 }

 application/view/ user.php



<?php


$query = $this->db->query("SELECT * FROM login;"); ?>


<div style="text-align:center">
<h1>User List</h1>
<table style="text-align:center;margin-left: 38%;">
<thead>
<tr>
<th> name</th>
<th> Email</th>
<th> Password</th>
<th> Address</th>
</tr>
</thead>
<tbody>

<?php
foreach ($query->result('User') as $user)
{ ?>
<tr>
 <td>
    <?=$user->name;?>
 </td>
 <td>
    <?=$user->email;?>
 </td>
  <td>
    <?=$user->pass;?>
 </td>
  <td>
    <?=$user->address;?>
 </td>

</tr>            
 <?php        
}
?>

</tbody>
</table>
</div>





No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...