Saturday, April 25, 2020

CodeIgniter PHP : Merge Array

There are condition when we have two array and want to combine them. In PHP, we can use function array_merge() to merge those to array.
Below is the example how to use the function.


<?php
    $a1=array("a"=>"red","b"=>"green");
    $a2=array("c"=>"blue","b"=>"yellow");
    print_r(array_merge($a1,$a2));
?>

Result :
Array ([a]=>red [b]=>yellow [c]=>blue)

As you can see there are two value for key=b. But the result is going to print the 2nd array array as the value.

Tuesday, October 15, 2019

MySQL Insert or Update column with value from another table

INSERT

Sometimes, there was an old data that need to be transfer from old table to new table. However, not all fields are required to transfer. So, below is the example of two tables and fields, and the sql statement.
tableOld
id     name     ic_no     phone_no     address
tableNew
id     name     ic_no     phone_no     

MySQL statement

INSERT INTO tableNew (name,ic_no,phone_no)
  SELECT name,ic_no,phone_no FROM tableOld 
  WHERE tableOld.id > 1;
This SQL statement is called as insert into select.


UPDATE

In this case, I want to get value from table1 to update into table2 based on certain condition or value.
For example :-
table1
id     name     ic_no     phone_no
table2
id     name     phone_no     address
I want to get phone_no from table1 and update the value phone_no into table2 with condition table2.name = table1.name.

MySQL statement
UPDATE table2 t2 
        INNER JOIN table1 t1 
             ON t2.name = t1.name
SET t2.ic_no= t1.ic_no
WHERE t2.name = t1.name;

Tuesday, February 26, 2019

Codeigniter How to make Onclick showHide Radio Button Function (Javascript)


All the code will be coded inside view file. First make your radio button.

<input type="radio" id="expense" name="transaction" onclick="ShowHideDiv()" checked /><?php echo lang('title_expense')?>
<input type="radio" id="income" name="transaction" onclick="ShowHideDiv()" /><?php echo lang('title_income')?>

Make sure the radio button have an id and the same name. Also put onclick that equal to function that you want. For this project we want ShowHideDiv  func.

Then make the div that you want to show or hide.

<div id="expense_list" style="block: none">
//anything that you want to put inside this div
//it can be table or something
</div >

<div id="income_list" style="show: none">
//anything that you want to put inside this div
//it can be table or something
</div >


Lastly make the jquery script to make the ShowHideDiv() func.

<script type="text/javascript">
function ShowHideDiv() {
    var expense = document.getElementById("expense");
    var income = document.getElementById("income");
    var expense_list = document.getElementById("expense_list");
    var income_list = document.getElementById("income_list");
    expense_list.style.display = expense.checked ? "block" : "none";
    income_list.style.display = income.checked ? "block" : "none";
}
</script>


"block" : "none"  - means the func to hide the content is block.
"show" : "none"  - means the func will show nothing.(hide content)

Monday, February 25, 2019

CodeIgniter How to Make send Email Function

First, make a hidden form of table id in view to call it at controller.

View

echo form_hidden('id', $table->id);


Then make a send_email function inside controller file.

Controller

  public function send_email($id)
  {
    $leave = $this->one_model->get('table', $id);
    $staff = $this->one_model->get('staff', $leave->created_by);
    $approver = $this->one_model->get('staff', $staff->leave_approver_id);
    $organization = $this->one_model->get('organizations', $leave->org_id);
    $apply_date = date_create($leave->created_at);
    $apply_date = date_format($apply_date, DATE_FORMAT);
    $date_start = date_create($leave->date_start);
    $date_start = date_format($date_start, DATE_FORMAT);
    $date_end = date_create($leave->date_end);
    $date_end = date_format($date_end, DATE_FORMAT);

    // construct msg - with invoice link inside
    $message = '

Permohonan cuti diterima seperti berikut:

Pemohon Cuti: '.$staff->name.'
Tarikh Permohonan: '.$apply_date.'
Tarikh Mula: '.$date_start.'
Tarikh Akhir: '.$date_end.'
Jumlah Hari: '.$leave->total_day.'
Sebab: '.$leave->reason.'

Untuk memberi maklum balas sila ke localhost/smap/lu/'.$leave->secure_id.'

Terima kasih';


    $this->load->library('mailgun');

    $this->mailgun->from("$organization->name<postmaster@mg.smap.my>");
    $this->mailgun->reply_to($organization->email);
    $this->mailgun->to($approver->email);
    $this->mailgun->bcc('hello@smap.my');

    $this->mailgun->subject("Permohonan Cuti ($staff->name)");
    $this->mailgun->message($message);

    $this->mailgun->send();

  }


Controller process

    $id = $post['id'];

    $this->send_email($id);



CodeIgniter How to make filter function

How to make filter function in PHP.

View

For view, first make the dropdown list and filter button.

<?php echo form_open(''); ?>
<table width="100%">
<tr>
<td align="right">
<?php echo form_dropdown('name', $array_list, $selected_array, 'class="form-control input-inline input-small"'); ?>
<input type="submit" value="<?php echo lang('lbl_filter'); ?>" class="btn btn-primary" />
</td>
</tr>
</table>
<?php echo form_close(); ?>


'name' = data name that will to represent the data and be used to call in controller.
$array_list = data that you want to display inside the dropdown.
$selected_array = array that you have select to filter.



Controller list

$data = array();

      $data['selected_array'] = '';
  
      if ($post = $this->input->post()) {
        $post = $post = $this->input->post();
        $data_name = $post['name']; //data name that hv been set in view
  
        if (!empty($name)) {
          $this->db->where("column in table = $data_name");
          $data['selected_array'] = $data_name;
        }
      }

This controller is used to set the filter function.

@getnada

@getnada

What is @getnada ?

An temporary email services to avoid spam. It is mean that we get a chances to create a temporary email address and remain active long enough for you to receive a reply from whoever the address was given to. Then you don't have to use it again.


How to use nada?

1. Go to @getnada.com
2. Click Add Inbox - put any names you want and choose any domain
3. Then paste the email created at any places you want
4. Inbox will received according your email created


Thursday, January 31, 2019

80-20 Rule

80-20 RULE EXPLAINED

The 80 20 rule, also known as Pareto Principle is one of the helpful concepts for life and management. This rule suggests that 20 percent of your activities will account for 80 percent of your result.

20% activities ===> 80% results.

How Does It Work ?

The concept suggests two out of ten items, on any general to-do list, will turn out to be worth more than the other eight items put together.

The sad fact is that most people do not focusing on the 20% of things that are most valuable and important but more focused on the 80% of that are least important.

How To Apply ?

1. First list down some thing that you want to do.

2. Then sort them according to the most important to the least important.

3. Lastly, start to do your work based on the most important task first. 

IONIC PASS PARAMETER

 To pass parameter to next page, first we need to make sure that we have 2 pages which is page from and page to. In page from ts file, you h...