Skip to main content

Posts

Difference between empty, null & isset

1. Null A variable is considered to be null if: it has been assigned the constant NULL. it has been unset(). it has not been set to any value yet. Note : empty array is converted to null by non-strict equal '==' comparison. Use is_null() or '===' if there is possible of getting empty array. eg: 1 $a = array(); $a == null  <== return true $a === null < == return false is_null($a) <== return false eg: 2 Note the following: $test =''; if (isset($test)){     echo 'Variable test exists'; } if (empty($test)){ // same result as $test = ''     echo ' and is_empty'; } if ($test == null){ // not the same result as is_null($test)     echo 'and is_null'; } The result would be: Variable test exists and is_empty and is_null eg : 3 But for the following code...: $test =''; if (isset($test)){     echo 'Variable test exists'; } if (empty($test)){ // same result as $test =...

MySql query used in projects

Mysql Query Helps you in Project 1. Copy data of one table to another  CREATE TABLE student2 SELECT * FROM student;     or CREATE TABLE student2 LIKE student; INSERT student2 SELECT * FROM student; 2. Copy structure of one table onto another but not data  CREATE TABLE student2 SELECT * FROM student WHERE 1=0 3. Insert data into table form another table on id basis   INSERT INTO student2 SELECT * FROM student WHERE id = 2; 4. Update the record in table Update students set first_name=’Sudhir’ where id=2; 5. Create table query CREATE TABLE IF NOT EXISTS `cities` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `country_id` int(10) unsigned DEFAULT NULL, `state_id` int(10) unsigned DEFAULT NULL, `name` varchar(100) NOT NULL DEFAULT '', `created` datetime DEFAULT NULL, `modified` datetime DEFAULT NULL, PRIMARY KEY (`id`), KEY `name` (`name`), KEY `country_id` (`country_id`) ) ENGINE=InnoDB 6. Delete Command DELET...

Save multiple rows record in cakephp

You can also use this format to save several records and their HABTM associations with  saveAll() , using an array like the following: Array ( [0] => Array ( [Note] => Array ( [id] => 0 [company_id] => 53218f2c-91f8-4168-a1d6-09b50a28b132 [cid] => 53199bf6-2e78-43c2-8a08-084f0a28b132 [author] => vh admin [notedate] => 2014-09-05 [time] => 16:08:46 [type] => client [type_id] => 53199bf6-2e78-43c2-8a08-084f0a28b132 [subject] => Inactivated [reason] => Feedback issues [message] => Views are the presentation layer in CakePHP. They convert the data fetched from Models into the output format requested by the client. Read more about ) ) [1] => Array ...

Softdelete behaviors in cakephp

<?php class SoftDeleteBehavior extends ModelBehavior { /**  * Default settings  *  * @var array $default  */ public $default = array('deleted' => 'deleted_date'); /**  * Holds activity flags for models  *  * @var array $runtime  */ public $runtime = array(); /**  * Setup callback  *  * @param object $model  * @param array $settings  */     public function setup(&$model, $settings = array()) {         if (empty($settings)) {             $settings = $this->default;         } elseif (!is_array($settings)) {             $settings = array($settings);         }         $error = 'SoftDeleteBehavior::setup(): model ' . $model->alias . ' has no field ';         $fields = $this->_normalizeFields($model, $settings)...

jQuery Autocomplete

<link rel="stylesheet" type="text/css" href="/css/jquery.autocomplete.css" /> <script src="js/jquery/jquery-1.7.1.min.js"></script> <script src="js/jquery/jquery.ui.autocomplete.min.js"></script> jQuery autocomplete with jSON <script>var data = [ {"label" : "Aragorn"}, {"label" : "Arwen"}, {"label" : "Bilbo Baggins"}, {"label" : "Boromir"}, {"label" : "Frodo Baggins"}, {"label" : "Gandalf"}, {"label" : "Gimli"}, {"label" : "Gollum"}, {"label" : "Legolas"}, {"label" : "Meriadoc Merry Brandybuck"}, {"label" : "Peregrin Pippin Took"}, {"label" : "Samwise Gamgee"} ]; </script> <script> $(function() { $( ...

Cakephp Model Attributes

useDbConfig: The useDbConfig property is a string that specifies the name of the database connection to use to bind your model class to the related database table. Example usage: class Example extends AppModel {     public $useDbConfig = 'alternate'; } useTable: The useTable property specifies the database table name. class Example extends AppModel {     public $useTable = false; // This model does not use a database table } Alternatively: class Example extends AppModel {     public $useTable = 'exmp'; // This model uses a database table 'exmp' } Order The default ordering of data for any find operation. Possible values include: $order = "field" $order = "Model.field"; $order = "Model.field asc"; $order = "Model.field ASC"; $order = "Model.field DESC"; $order = array("Model.field" => "asc", "Model.field2" => "DESC"); virtualFields Array of virtual fields this model h...

Pagination with MySql, jQuery & Php

Ajax pagination with MySQL, PHP and jQuery Method 1: Javascript : <script type="text/javascript"> $(document).ready(function(){ function loading_show(){ $('#loading').html("<img src='images/loading.gif'/>").fadeIn('fast'); } function loading_hide(){ $('#loading').fadeOut('fast'); }                 function loadData(page){ loading_show();                     $.ajax ({ type: "POST", url: "load_data.php", data: "page="+page, success: function(msg) { $("#container").ajaxComplete(function(event, request, settings) { loading_hide(); $("#container").html(msg); }); } }); } loadData(1);  $('#container .pagination li.active').on('click',function(){ var page = $(this).attr('p'); loadData(page); }); }); </script> ...