Topic: Mysqli

PHP Codeigniter 3 Multiple WHERE conditions Example 0

PHP Codeigniter 3 Multiple WHERE conditions Example

Today, We want to share with you PHP Codeigniter 3 Multiple WHERE conditions Example.In this post we will show you codeigniter 3 Multiple WHERE Clause with Examples, hear for CodeIgniter 3 PHP $this->db->where() Multiple AND Conditions we will give you demo and example for implement.In this post, we will learn about CodeIgniter 3 Active Record multiple “where” and “or” statements with an example.

PHP Codeigniter 3 Multiple WHERE conditions Example

There are the Following The simple About PHP Codeigniter 3 Multiple WHERE conditions Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to use multiple where condition in Codeigniter?, so the some major files and Directory structures for this example is following below.This codeigniter 3 function enables you to set simple WHERE multiple conditions clauses using one List of four methods:

  • using Simple key/value method
  • using Custom key/value method
  • using Associative array method
  • using Custom string:

Example 1: multiple condition in where clause in codeigniter 3

Custom key/value method via multiple condition in where clause in codeigniter 3

$multipleCIWhere = ['name' => $name, 'email' => $useremail, 'isactive' => $isactive];
$this->db->where($multipleCIWhere);
$this->db->get("pakainfo_tblName");

Example 2: codeigniter 3 multiple where condition

Simple key/value method via codeigniter 3 multiple where condition

$multipleCIWhere = ['name !=' => $name, 'id <' => $id, 'isactive >' => $isactive];
$this->db->where($multipleCIWhere);
$this->db->get("pakainfo_tblName");

Example 3: Associative array method

multiple where condition codeigniter using Associative array method

$multipleCIWhere = array('name' => $name, 'title' => $title, 'isactive' => $isactive);

$this->db->where($multipleCIWhere); 

// Produces: WHERE name = 'Jaydeep' AND title = 'Gondaliya' AND isactive = 'active'

Example 4: Custom string:

multiple where condition codeigniter using Custom string

$where = "name='Jaydeep' AND title='Gondaliya' OR isactive='active'";
$this->db->where($where);

Codeigniter 3 Query Builder Class

PHP Codeigniter 3 Multiple WHERE conditions Source code

PHP Codeigniter 3 Multiple WHERE conditions Example - PHP Codeigniter 3 Multiple WHERE conditions Example

PHP Codeigniter 3 Multiple WHERE conditions Example

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Codeigniter 3 Multiple WHERE conditions Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

CodeIgniter CRUD Example Tutorial From Scratch 0

CodeIgniter CRUD Example Tutorial From Scratch

Today, We want to share with you CodeIgniter CRUD Example Tutorial From Scratch.In this post we will show you CodeIgniter AJAX CRUD using Bootstrap Modal Edit or Update, hear for Codeigniter Ajax Crud using DataTables – Delete – Remove Mysql Data we will give you demo and example for implement.In this post, we will learn about How to Create CURD Operation in Codeigniter with AJAX and Bootstrap with an example.

CodeIgniter CRUD Example Tutorial From Scratch

There are the Following The simple About CodeIgniter CRUD Example Tutorial From Scratch Full Information With Example and source code.

As I will cover this Post with live Working example to develop CodeIgniter CRUD using Ajax,Bootstrap,Models and MySQL, so the some major files and Directory structures for this example is following below.

  • CodeIgniter Database and Table
  • CodeIgniter constructor
  • Create CodeIgniter Controller
  • Make CodeIgniter Model
  • CodeIgniter CRUD(Create, Read, Update and Delete)

Step 1 : Create database and Table

create CodeIgniter the database for simple project

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as create a table members using this SQL code..

Table structure for table `members`

CREATE TABLE `members` (
  `member_id` int(11) NOT NULL,
  `member_name` int(11) NOT NULL,
  `member_title` varchar(50) NOT NULL,
  `member_fname` varchar(50) NOT NULL,
  `member_category` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Step 2 : Dump Data for Members

Fake data for table “members”

INSERT INTO `members` (`member_id`, `member_name`, `member_title`, `member_fname`, `member_category`) VALUES
(2, 7893, 'Gondaliya Jaydeep', 'Jaydeep', 'devloping'),
(3, 8934, 'Hardik patel', 'Ankit', 'devloping'),
(6, 8902, 'bhavna patadiya', 'Krunal', 'testing'),
(7, 2345, 'Mayur Dhameliya', 'shah manshi', 'Designer'),
(8, 8927, 'sejal Ramani', 'Hiren', 'Designer'),
(9, 6723, 'chirag dethariya', 'Sir Vishal Pandya', 'testing'),
(10, 7896, 'Ankit kalariya', 'Deepali ', 'devloping'),
(11, 8978, 'Krunal sisodiya', 'jalpa patadiya', 'Mobile devloping'),
(12, 8987, 'Dhaval dave', 'Sir Jd patel', 'Physics'),
(13, 7890, 'vivek bharat bhai sojitra', 'Vivek kalariya', 'devloping'),
(14, 1234, 'Chandni umasanakar joshi', 'chandni joshi', 'devloping');

Step 3 : Create a CodeIgniter constructor

Make CodeIgniter constructor __construct()

public function __construct()
	 	{
	 		parent::__construct();
			$this->load->helper('url');
	 		$this->load->model('member_model');
	 	}

CodeIgniter models

	public function index()
	{
 
		$data['members']=$this->member_model->get_all_members();
		$this->load->view('member_view',$data);
	}

Member_add() method

public function member_add()
		{
			$data = array(
					'member_name' => $this->input->post('member_name'),
					'member_title' => $this->input->post('member_title'),
					'member_fname' => $this->input->post('member_fname'),
					'member_category' => $this->input->post('member_category'),
				);
			$insert = $this->member_model->member_add($data);
			echo json_encode(array("status" => TRUE));
		}

Ajax_edit() method

public function ajax_edit($id)
		{
			$data = $this->member_model->get_by_id($id);



			echo json_encode($data);
		}

Member_update() method

public function member_update()
	{
		$data = array(
				'member_name' => $this->input->post('member_name'),
				'member_title' => $this->input->post('member_title'),
				'member_fname' => $this->input->post('member_fname'),
				'member_category' => $this->input->post('member_category'),
			);
		$this->member_model->member_update(array('member_id' => $this->input->post('member_id')), $data);
		echo json_encode(array("status" => TRUE));
	}

Member_delete method

public function member_delete($id)
	{
		$this->member_model->delete_by_id($id);
		echo json_encode(array("status" => TRUE));
	}

Step 4 : CodeIgniter Controller (CodeIgniter CRUD Example Tutorial)

Member controller for CodeIgniter CRUD Example Tutorial

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Member extends CI_Controller {


	 public function __construct()
	 	{
	 		parent::__construct();
			$this->load->helper('url');
	 		$this->load->model('member_model');
	 	}


	public function index()
	{

		$data['members']=$this->member_model->get_all_members();
		$this->load->view('member_view',$data);
	}
	public function member_add()
		{
			$data = array(
					'member_name' => $this->input->post('member_name'),
					'member_title' => $this->input->post('member_title'),
					'member_fname' => $this->input->post('member_fname'),
					'member_category' => $this->input->post('member_category'),
				);
			$insert = $this->member_model->member_add($data);
			echo json_encode(array("status" => TRUE));
		}
		public function ajax_edit($id)
		{
			$data = $this->member_model->get_by_id($id);



			echo json_encode($data);
		}

		public function member_update()
	{
		$data = array(
				'member_name' => $this->input->post('member_name'),
				'member_title' => $this->input->post('member_title'),
				'member_fname' => $this->input->post('member_fname'),
				'member_category' => $this->input->post('member_category'),
			);
		$this->member_model->member_update(array('member_id' => $this->input->post('member_id')), $data);
		echo json_encode(array("status" => TRUE));
	}

	public function member_delete($id)
	{
		$this->member_model->delete_by_id($id);
		echo json_encode(array("status" => TRUE));
	}



}

get_all_members() function

public function get_all_members()
{
$this->db->from('members');
$query=$this->db->get();
return $query->result();
}

Retrive single a member record

	public function get_by_id($id)
	{
		$this->db->from($this->table);
		$this->db->where('member_id',$id);
		$query = $this->db->get();

		return $query->row();
	}

Insert a member_add($data) method

	public function member_add($data)
	{
		$this->db->insert($this->table, $data);
		return $this->db->insert_id();
	}

update member_update($where, $data)

	public function member_update($where, $data)
	{
		$this->db->update($this->table, $data, $where);
		return $this->db->affected_rows();
	}

delete_by_id($id) function

	public function delete_by_id($id)
	{
		$this->db->where('member_id', $id);
		$this->db->delete($this->table);
	}

Step 5 : CodeIgniter Member Model

complete Member Model source code for CodeIgniter CRUD Example Tutorial

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

class Member_model extends CI_Model
{

	var $table = 'members';


	public function __construct()
	{
		parent::__construct();
		$this->load->database();
	}


public function get_all_members()
{
$this->db->from('members');
$query=$this->db->get();
return $query->result();
}


	public function get_by_id($id)
	{
		$this->db->from($this->table);
		$this->db->where('member_id',$id);
		$query = $this->db->get();

		return $query->row();
	}

	public function member_add($data)
	{
		$this->db->insert($this->table, $data);
		return $this->db->insert_id();
	}

	public function member_update($where, $data)
	{
		$this->db->update($this->table, $data, $where);
		return $this->db->affected_rows();
	}

	public function delete_by_id($id)
	{
		$this->db->where('member_id', $id);
		$this->db->delete($this->table);
	}


}

Step 6 : Display List View For CodeIgniter CRUD Example Tutorial

Create a member_view.php

<!DOCTYPE html>
<html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>CodeIgniter CRUD Example Tutorial From Scratch</title>
    <link href="<?php echo base_url('assests/bootstrap/css/bootstrap.min.css')?>" rel="stylesheet">
    <link href="<?php echo base_url('assests/datatables/css/dataTables.bootstrap.css')?>" rel="stylesheet">
  </head>
  <body>


  <div class="container">
    <h1>CodeIgniter CRUD Example Tutorial From Scratch</h1>
</center>
    <h3>Member Store</h3>
    <br />
    <button class="btn btn-success" onclick="add_member()"><i class="glyphicon glyphicon-plus"></i> Add Member</button>
    <br />
    <br />
    <table id="table_id" class="table table-striped table-bordered" cellspacing="0" width="100%">
      <thead>
        <tr>
					<th>Member ID</th>
					<th>Member Name</th>
					<th>Member Title</th>
					<th>Member Fname</th>
					<th>Member Category</th>

          <th style="width:125px;">Action
          </p></th>
        </tr>
      </thead>
      <tbody>
				<?php foreach($members as $member){?>
				     <tr>
				         <td><?php echo $member->member_id;?></td>
				         <td><?php echo $member->member_name;?></td>
								 <td><?php echo $member->member_title;?></td>
								<td><?php echo $member->member_fname;?></td>
								<td><?php echo $member->member_category;?></td>
								<td>
									<button class="btn btn-warning" onclick="edit_member(<?php echo $member->member_id;?>)"><i class="glyphicon glyphicon-pencil"></i></button>
									<button class="btn btn-danger" onclick="delete_member(<?php echo $member->member_id;?>)"><i class="glyphicon glyphicon-remove"></i></button>


								</td>
				      </tr>
				     <?php }?>



      </tbody>

      <tfoot>
        <tr>
          <th>Member ID</th>
          <th>Member Name</th>
          <th>Member Title</th>
          <th>Member Fname</th>
          <th>Member Category</th>
          <th>Action</th>
        </tr>
      </tfoot>
    </table>

  </div>

  <script src="<?php echo base_url('assests/<a href="https://www.phpcodify.com/category/jquery/">jquery</a>/jquery-3.1.0.min.js')?>"></script>
  <script src="<?php echo base_url('assests/bootstrap/js/bootstrap.min.js')?>"></script>
  <script src="<?php echo base_url('assests/datatables/js/jquery.dataTables.min.js')?>"></script>
  <script src="<?php echo base_url('assests/datatables/js/dataTables.bootstrap.js')?>"></script>


  <script type="text/javascript">
  $(document).ready( function () {
      $('#table_id').DataTable();
  } );
    var save_method; //for save method string
    var table;


    function add_member()
    {
      save_method = 'add';
      $('#form')[0].reset();
      $('#memberFrm').modal('show');
    }

    function edit_member(id)
    {
      save_method = 'update';
      $('#form')[0].reset(); 

      $.ajax({
        url : "<?php echo site_url('index.php/member/ajax_edit/')?>/" + id,
        type: "GET",
        dataType: "JSON",
        success: function(data)
        {

            $('[name="member_id"]').val(data.member_id);
            $('[name="member_name"]').val(data.member_name);
            $('[name="member_title"]').val(data.member_title);
            $('[name="member_fname"]').val(data.member_fname);
            $('[name="member_category"]').val(data.member_category);


            $('#memberFrm').modal('show');
            $('.modal-title').text('Edit Member');

        },
        error: function (jqXHR, textStatus, errorThrown)
        {
            alert('Error get data from ajax');
        }
    });
    }



    function save()
    {
      var url;
      if(save_method == 'add')
      {
          url = "<?php echo site_url('index.php/member/member_add')?>";
      }
      else
      {
        url = "<?php echo site_url('index.php/member/member_update')?>";
      }

          $.ajax({
            url : url,
            type: "POST",
            data: $('#form').serialize(),
            dataType: "JSON",
            success: function(data)
            {
               $('#memberFrm').modal('hide');
              location.reload();
            },
            error: function (jqXHR, textStatus, errorThrown)
            {
                alert('Error adding / update data');
            }
        });
    }

    function delete_member(id)
    {
      if(confirm('Are you sure delete this data?'))
      {
          $.ajax({
            url : "<?php echo site_url('index.php/member/member_delete')?>/"+id,
            type: "POST",
            dataType: "JSON",
            success: function(data)
            {
               
               location.reload();
            },
            error: function (jqXHR, textStatus, errorThrown)
            {
                alert('Error deleting data');
            }
        });

      }
    }

  </script>

  <div class="modal fade" id="memberFrm" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
        <h3 class="modal-title">Member Form</h3>
      </div>
      <div class="modal-body form">
        <form action="#" id="form" class="form-horizontal">
          <input type="hidden" value="" name="member_id"/>
          <div class="form-body">
            <div class="form-group">
              <label class="control-label col-md-3">Member Name</label>
              <div class="col-md-9">
                <input name="member_name" placeholder="Member Name" class="form-control" type="text">
              </div>
            </div>
            <div class="form-group">
              <label class="control-label col-md-3">Member Title</label>
              <div class="col-md-9">
                <input name="member_title" placeholder="Member_title" class="form-control" type="text">
              </div>
            </div>
            <div class="form-group">
              <label class="control-label col-md-3">Member Fname</label>
              <div class="col-md-9">
								<input name="member_fname" placeholder="Member Fname" class="form-control" type="text">

              </div>
            </div>
						<div class="form-group">
							<label class="control-label col-md-3">Member Category</label>
							<div class="col-md-9">
								<input name="member_category" placeholder="Member Category" class="form-control" type="text">

							</div>
						</div>

          </div>
        </form>
          </div>
          <div class="modal-footer">
            <button type="button" id="btnSave" onclick="save()" class="btn btn-primary">Save</button>
            <button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
          </div>
        </div>
      </div>
    </div>

  </body>
</html>

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about CodeIgniter CRUD Example Tutorial From Scratch.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

PHP Codeigniter Insert Multiple Records Into MySQL 0

PHP Codeigniter Insert Multiple Records Into MySQL

Today, We want to share with you PHP Codeigniter Insert Multiple Records Into MySQL.In this post we will show you How to insert multiple rows in Codeigniter, hear for PHP Codeigniter Inserting Multiple Records Into a Table we will give you demo and example for implement.In this post, we will learn about Codeigniter batch insert, multiple insert in codeigniter with an example.

PHP Codeigniter Insert Multiple Records Into MySQL

There are the Following The simple About PHP Codeigniter Insert Multiple Records Into MySQL Full Information With Example and source code.

As I will cover this Post with live Working example to develop codeigniter unable to insert multiple row data to database , so the some major files and Directory structures for this example is following below.

  • Insert Multiple Records
  • using insert_batch() in CodeIgniter

Insert Multiple Records:

MySQL insert multiple rows in codeigniter Example

$membersArray = [
   [
      'name' => 'Jaydeep Gondaliya',
      'detail' => 'Angularjs developer'
   ],
   [
      'name' => 'Krunal Sisodiya',
      'detail' => 'Asp.Net developer'
   ]
];
$this->db->insert_batch('member_listTbl', $membersArray); 

Insert multiple rows with CodeIgniter

codeigniter active your record has a simple function Like insert_batch(). with INSERT multiple records without cycle in CodeIgniter

	
$devloperArray = array(
   array(
      'title' => 'Pakainfo website' ,
      'name' => 'Jaydeep Gondaliya' ,
      'date' => '25-04-1992'
   ),
   array(
      'title' => 'Infinityknow Website' ,
      'name' => 'Jaydeep Patel' ,
      'date' => '17-07-1991'
   )
);
 
$this->db->insert_batch('devloper_tbl', $devloperArray); 
 
// Produces: INSERT INTO devloper_tbl (title, name, date) VALUES ('Pakainfo website', 'Jaydeep Gondaliya', '25-04-1992'), ('Infinityknow Website', 'Jaydeep Patel', '17-07-1991')

PHP Codeigniter Insert Multiple Records Into MySQL Source code

Insert multiple rows with CodeIgniter - PHP Codeigniter Insert Multiple Records Into MySQL

Insert multiple rows with CodeIgniter

Insert multiple rows with CodeIgniter
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Codeigniter Insert Multiple Records Into MySQL.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

PHP Vue.js Live Search Box Using MySQL 0

PHP Vue.js Live Search Box Using MySQL

PHP Vue.js Live Search Box Using MySQL

In this Post We Will Explain About is PHP Vue.js Live Search Box Using MySQL With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Live Search using Vue.js with PHP Example

In this post we will show you Best way to implement VueJS Ajax Live Search With PHP and MySQL, hear for VueJS Build Live Search Box Using PHP, MySQL And AJAX with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

PHP Vue.js Live Search Box Using MySQL

In this Example,First of all Add or Include External Libs Like as a(jQuery, css etc..), and then create a simple index.php or index.html page.After that crate a simple javascript file like as a index.js or main.js, It is also add your web-application First Header Part to some priority set.After that Include your relevant CSS Class.

Creating Simple Database

CREATE TABLE `users` (
  `userid` INT(11) NOT NULL AUTO_INCREMENT,
  `userfname` VARCHAR(30) NOT NULL,
  `userlname` VARCHAR(30) NOT NULL,
PRIMARY KEY(`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Inserting Data into our Database

INSERT INTO `users` (`userid`, `userfname`, `userlname`) VALUES
(1, 'krunal', 'sisodiya'),
(2, 'jaydeep', 'Gondaliya'),
(3, 'ankit', 'kathiriya'),
(4, 'chirag', 'Dethariya');

index.php



	<title>PHP Vue.js Live Search Box Using MySQL</title>
3.3.7/css/bootstrap.min.css
vue/2.5.10/vue.min.js
axios.min.js


<div id="mymain">
	<div class="container">
		<h1 class="page-header text-center"></h1>
		<div class="col-xl-8 col-xl-offset-2">
			<div class="row">
				<div class="col-xl-4 col-xl-offset-8">
					
				</div>
			</div>
			<div style="height:15px"></div>
			<table class="table table-bordered table-striped">
				<thead>
					<th>USER Firstname</th>
					<th>USER Lastname</th>
				</thead>
				<tbody>
 
						<tr>
							<td colspan="2" align="right">No user match your search</td>
						</tr>
 
					<tr>
						<td>{{ user.userfname }}</td>
						<td>{{ user.userlname }}</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</div>



main.js

var main = new Vue({
	el: '#mymain',
	data:{
		users: [],
		search: {queryStr: ''},
		nouser: false
	},
 
	mounted: function(){
		this.fetchUsers();
	},
 
	methods:{
		checkSearch: function() {
			var queryStr = main.toFormData(main.search);
	   		axios.post('do_action.php?do_action=search', queryStr)
				.then(function(results){
					main.users = results.data.users;
 
					if(results.data.users == ''){
						main.nouser = true;
					}
					else{
						main.nouser = false;
					}
				});
       	},
 
       	fetchUsers: function(){
			axios.post('do_action.php')
				.then(function(results){
					main.users = results.data.users;
				});
       	},
 
		toFormData: function(obj){
			var liveForm = new FormData();
			for(var key in obj){
				liveForm.mainend(key, obj[key]);
			}
			return liveForm;
		},
 
	}
});

do_action.php

connect_error) {
    die("Connection failed: " . $db_con->connect_error);
}
 
$output = array('error' => false);
 
$do_action="show";
 
if(isset($_GET['do_action'])){
	$do_action=$_GET['do_action'];
}
 
if($do_action=='show'){
	$sql = "select * from users";
	$query = $db_con->query($sql);
	$users = array();
 
	while($data_row = $query->fetch_array()){
		array_push($users, $data_row);
	}
 
	$output['users'] = $users;
}
 
if($do_action=='search'){
	$queryStr=$_POST['queryStr'];
	$sql="select * from users where userfname like '%$queryStr%' or userlname like '%$queryStr%'";
	$query = $db_con->query($sql);
	$users = array();
 
	while($data_row = $query->fetch_array()){
		array_push($users, $data_row);
	}
 
	$output['users'] = $users;
}
 
$db_con->close();

//return simple json format and data display 
header("Content-type: mainlication/json");
echo json_encode($output);
die();
 
?>

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Example

I hope you have Got What is How to Integrate live search in PHP and MySQL with VueJS And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.

Angular DataTable Pagination Searching Sorting in PHP 0

Angular DataTable Pagination Searching Sorting in PHP MySQLi Example

Today, We want to share with you Angular DataTable Pagination Searching Sorting in PHP MySQLi.In this post we will show you AngularJS Datatable Pagination, Sorting and Searching Using Ajax, hear for Pagination Searching and Sorting of data table using Angularjs PHP MySQLi we will give you demo and example for implement.In this post, we will learn about Angular DataTable server side sorting,pagination and searching using PHP and MySQLi with an example.

Angular DataTable Pagination Searching Sorting in PHP MySQLi

There are the Following The simple About Angular DataTable Pagination Searching Sorting in PHP MySQLi Full Information With Example and source code.

As I will cover this Post with live Working example to develop angular – datatable [Pagination, Sorting in Angular], so the some major files and Directory structures for this example is following below.

  • index.php

Step 1: Make MySQL Database table

CREATE TABLE IF NOT EXISTS `members` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `member_pos` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `member_area` text COLLATE utf8_unicode_ci NOT NULL,
  `member_details` text COLLATE utf8_unicode_ci NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=537 

Step 2: Make HTML interFace

index.php

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.php.

<!doctype html>
<html>
<head>
    <title>Angular DataTable Pagination Searching Sorting in PHP MySQLi - pakainfo.com</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
</head>
<body>
    <div ng-app="pakainfoApp" ng-controller="controller">
        <div class="container">
            <hr/>
            <h2 align="center">Angular DataTable Pagination Searching Sorting in PHP MySQLi - pakainfo.com</a></h2>
            <hr/>
            <div class="row">
                <div class="col-md-6 pull-right">
                    <label>Search:</label>
                    <input type="text" ng-model="search" ng-change="filter()" placeholder="Please Enter Keyword and Search" class="form-control" />
                </div>
            </div>
            <hr/>
            <!-- All list of member data list-->
            <div class="row">
                <div class="col-md-12" ng-show="preview_data > 0">
                    <table class="table">
                        <thead>
                            <th>Name<a ng-click="member_sort('name');"><i class="glyphicon glyphicon-sort"></i></a></th>
                            <th>Slug<a ng-click="member_sort('member_pos');"><i class="glyphicon glyphicon-sort"></i></a></th>
                        </thead>
                        <tbody>
                            <tr dir-paginate="mdata in member_search = (file | filter:search | orderBy : base :reverse | itemsPerPage:10)">
                                <td>{{mdata.member_pos}}</td>
                                <td>{{mdata.name}}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <!-- Show message if no found any data Members -->
                <div class="col-md-12" ng-show="preview_data == 0">
                    <div class="col-md-12">
                        <h4>No Members found..</h4>
                    </div>
                </div>
                <!-- Show member pagination data Members -->
                <div class="col-md-12">
                    <div class="col-md-6" ng-show="preview_data > 0">
                        <dir-pagination-controls
                           max-size="5"
                           direction-links="true"
                           boundary-links="true" >
                        </dir-pagination-controls>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Include Angularjs External Libs -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.5.0/ui-bootstrap-tpls.min.js"></script>
    <script src="dirPagination.js"></script>
    <script src="pakainfoapp.js"></script>
</body>
</html>

Step 3: Make JavaScript file

Create pakainfoapp.js file

var pakainfoApp = angular.module('pakainfoApp', ['ui.bootstrap', 'angularUtils.directives.dirPagination']);
pakainfoApp.filter('flagning_data', function() {
    return function(val, flag) {
        if (val) {
            flag = +flag;
            return val.slice(flag);
        }
        return [];
    }
});
pakainfoApp.controller('controller', function($scope, $http, $timeout) {
    $http.get('ajax_fetch.php').then(successCallback, errorCallback);
    function successCallback(results){
        //angularjs controller success code
        $scope.file = results.data;
        $scope.gridData = 1;
        $scope.total_limit = 10;
        $scope.preview_data = $scope.file.length;
        console.log($scope.file.length);
        $scope.total_users = $scope.file.length;
    }
    function errorCallback(error){
        //error code
    }
    $scope.pos_page = function(parm_pageno) {
        console.log(parm_pageno);
        $scope.gridData = parm_pageno;
    };
    $scope.filter = function() {
        $timeout(function() {
            $scope.preview_data = $scope.member_search.length;
        }, 20);
    };
    $scope.member_sort = function(base) {
        $scope.base = base;
        $scope.reverse = !$scope.reverse;
    };
});

Step 4: Make Server Side Response

Create ajax_fetch.php file

<?php
$db_conn  = new mysqli('localhost', 'root', 'atmiya25', 'pakainfo12365');
$sqlQuery = "select member_pos, name from members order by id";
$data_res = $db_conn->query($sqlQuery) or die($db_conn->error . __LINE__);
$getData = [];
if ($data_res->num_rows > 0) {
    while ($myrow = $data_res->fetch_assoc()) {
        $getData[] = $myrow;
    }
}
$response = json_encode($getData);
echo $response;
?>

Angular DataTable Pagination Searching Sorting in PHP MySQLi – Output

Angular DataTable Pagination Searching Sorting in PHP MySQLi - Angular DataTable Pagination Searching Sorting in PHP

Angular DataTable Pagination Searching Sorting in PHP MySQLi

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Angular DataTable Pagination Searching Sorting in PHP MySQLi.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.