Wednesday, 24 August 2016

Codeigniter group by multiple columns

$this->db->group_by()

Permits you to write the GROUP BY portion of your query:

$this->db->group_by("title"); // Produces: GROUP BY title 
 
You can also pass an array of multiple values as well:

$this->db->group_by(array("title", "date"));  // Produces: GROUP BY title, date

Get last executed query in MySQL with PHP/CodeIgniter

$this->db->last_query();
Returns the last query that was run (the query string, not the result).
  
Example:
         $str = $this->db->last_query();

Wednesday, 17 August 2016

jQuery validation plugin multiple email addresses

<form id="form" method="post">
Het e-mailadres van je vriend(in):<input type="text" name="emails" id="emails" class="emails"><br />
<input type="submit" value="Verstuur">
</form>
jQuery.validator.addMethod(
    "multiemails",
     function(value, element) {
         if (this.optional(element)) // return true on optional element
             return true;
         var emails = value.split(/[;,]+/); // split element by , and ;
         valid = true;
         for (var i in emails) {
             value = emails[i];
             valid = valid &&
                     jQuery.validator.methods.email.call(this, $.trim(value), element);
         }
         return valid;
     },

   jQuery.validator.messages.multiemails
);

$("#form").validate({
     rules: {
                emails: { required: true, multiemails: true }
            },
     messages: {
                    emails: {
                                required: "enter the email",
                                multiemails: "Not Valid email"
                            }
               }

});

Disable automatic sorting on the first column when using jQuery DataTables

Set the aaSorting option to an empty array. It will disable initial sorting, whilst still allowing manual sorting when you click on a column.

"aaSorting": []

You just need to add the following parameter to the DataTables options:

 "order": []

Set up your DataTable as follows in order to override the default setting:
 
$('#example').dataTable( { "order": [], // Your other options here... } );

Friday, 12 August 2016

Converting string to Date and DateTime

Use strtotime() on your first date then date('Y-m-d') to convert it back:
$time = strtotime('10/15/2003');

$newformat = date('Y-m-d',$time);

echo $newformat;
// 2003-10-15

Wednesday, 10 August 2016

check / uncheck checkbox using jquery

Check/uncheck a checkbox, use the attribute checked 
$('#myCheckbox').attr('checked', true); // Checks it
$('#myCheckbox').attr('checked', false); // Unchecks it

Git merge branch to another branch

$ git checkout develop $ git pull $ git checkout test-branch $ git merge develop $ git push