Friday, September 27, 2019

Convert mysql to mysqli

Today to want to share how i convert from old system that using mysql to mysqli..

First this is for config file.

mysql



mysqli

 

changes also have to do in fn file

mysql



mysqli



Can you see the different that you have to add or adjust a bit.

in your files where your actual code to show add those file in the beginning.

<?php
session_start();
include_once 'include/config.php';
include_once 'include/fn.php';
?>

like this.
 

connect to MySqli using class

Today I want to show you guys how to connect to mysqli using class. You need to have 3 files.

config.php (your database connection)



fn.php (act as controller)



index.php (this is where you files are)



I'm using this code when i have to convert the old system in PHP 5.2 to PHP 7.1..
Amazingly it works.

Sunday, September 22, 2019

How to create new running number for specific code

 
Hello and Assalamualaikum,
 
 
Here a tip for you guys to try it out..
 
 
Hope it will give some idea for you guys..
 
 
The Code Like This
 
 
JGS0001
 
 
and you have to make it the running number from it.. with code GS is come from the group code (kodkumpulan) on selected value..
 
 
here the code..
 
 
 
the new code will be
 
JGS0002
 
 


Enjoy, Hope this post will be benefit for all of you. Thank You.










Sya Ahmad
Programmer in Ministry of Health


Export to Excel with PHPExcel using Codeigniter

Assalamualaikum/ Hello,

In this post I would like to show how to export data from MySQL to Excel with PHPExcel using Codeigniter.


In Controller

<?php

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

class Excel_export extends CI_Controller {

 function index()

 {

  $this->load->model("excel_export_model");

  $data["employee_data"] = $this->excel_export_model->fetch_data();

  $this->load->view("excel_export_view", $data);

 }

 function action()

 {

  $this->load->model("excel_export_model");

  $this->load->library("excel");

  $object = new PHPExcel();

  $object->setActiveSheetIndex(0);

  $table_columns = array("Name", "Address", "Gender", "Designation", "Age");

  $column = 0;

  foreach($table_columns as $field)

  {

   $object->getActiveSheet()->setCellValueByColumnAndRow($column, 1, $field);

   $column++;

  }

  $employee_data = $this->excel_export_model->fetch_data();

  $excel_row = 2;

  foreach($employee_data as $row)

  {

   $object->getActiveSheet()->setCellValueByColumnAndRow(0, $excel_row, $row->name);

   $object->getActiveSheet()->setCellValueByColumnAndRow(1, $excel_row, $row->address);

   $object->getActiveSheet()->setCellValueByColumnAndRow(2, $excel_row, $row->gender);

   $object->getActiveSheet()->setCellValueByColumnAndRow(3, $excel_row, $row->designation);

   $object->getActiveSheet()->setCellValueByColumnAndRow(4, $excel_row, $row->age);

   $excel_row++;

  }

  $object_writer = PHPExcel_IOFactory::createWriter($object, 'Excel5');

  header('Content-Type: application/vnd.ms-excel');

  header('Content-Disposition: attachment;filename="Employee Data.xls"');

  $object_writer->save('php://output');

 }
}


In Views


<html>
<head>
    <title>Export Data to Excel in Codeigniter using PHPExcel</title>
</head>
<body>
 <div class="container box">
  <h3 align="center">Export Data to Excel in Codeigniter using PHPExcel</h3>
  <br />
  <div class="table-responsive">
   <table class="table table-bordered">
    <tr>
     <th>Name</th>
     <th>Address</th>
     <th>Gender</th>
     <th>Designation</th>
     <th>Age</th>
    </tr>
    <?php
    foreach($employee_data as $row)
    {
     echo '
     <tr>
      <td>'.$row->name.'</td>
      <td>'.$row->address.'</td>
      <td>'.$row->gender.'</td>
      <td>'.$row->designation.'</td>
      <td>'.$row->age.'</td>
     </tr>
     ';
    }
    ?>
   </table>
   <div align="center">
    <form method="post" action="<?php echo base_url(); ?>excel_export/action">
     <input type="submit" name="export" class="btn btn-success" value="Export" />
    </form>
   </div>
   <br />
   <br />
  </div>
 </div>
</body>
</html>



In Models


<?php
class Excel_export_model extends CI_Model
{
 function fetch_data()
 {
  $this->db->order_by("id", "DESC");
  $query = $this->db->get("employee");
  return $query->result();
 }


}

And Last of all, you need to have to PHPExcel class to make it works..

There the link https://github.com/PHPOffice/PHPExcel

Enjoy, Hope this post will be benefit for all of you. Thank You.










Sya Ahmad
Programmer in Ministry of Health


Upload file using Codeigniter (Excel)

Assalamualaikum/Hello,

In this post I would like to show how to upload a file using codeigniter.

In Controller


public function add() {

  $config = array(
'upload_path' => "./uploads/excel/",
'allowed_types' => "xls|xlsx",
'max_size' => "5000" 
);
$this->load->library('upload', $config);
if($this->upload->do_upload('userfile'))
{
$data = array('upload_data' => $this->upload->data());
}
else
{
$error = array('error' => $this->upload->display_errors());
echo $this->upload->display_errors();
}
}


Important Factors You Need To Consider:

•File/Directory Permission: You must need to make sure that, where you want the uploaded file to be saved, php has proper write permission on those directories. Generally a ‘755’ or ‘777’ permission works fine.


Enjoy, Hope this post will be benefit for all of you. Thank You.










Sya Ahmad
Programmer in Ministry of Health


Dropdown Select with Codeigniter

Hello and Assalamualaikum,
Here a tip for to make a dropdown select with Codeigniter..
the output as below :-

as you click on the dropdown, the list will show on the selected data you want.


now, I will show you how to code it in your program..

In View (Codeigniter)


In View - JavaScript Section (Codeigniter)


In Controller (Codeigniter)



Okey..that all.. ;-) Thank you viewing..





LinkWithin

Related Posts Plugin for WordPress, Blogger...