Skip to main content

Posts

Jquery Ajax method

AJAX = Asynchronous JavaScript and XML. AJAX is about loading data in the background and display it on the webpage, without reloading the whole page. The ajax() method is used to perform an AJAX (asynchronous HTTP) request. Notes: Asynchronous means that the script will send a request to the server, and continue it's execution without waiting for the reply. As soon as reply is received a browser event is fired, which in turn allows the script to execute associated actions. The serialize() method creates a URL encoded text string by serializing form values readyState  Holds the status of the XMLHttpRequest. Changes from 0 to 4: 0: request not initialized 1: server connection established 2: request received 3: processing request 4: request finished and response is ready The parameters specifies: beforeSend(xhr): A function to run before the request is sent eg: beforeSend: function() {     xhr.setRequestHeader("Accept", "text/javascr...

Fetch IP address & country

Function to fetch ip address function get_ip() { $ipaddress = ''; if (getenv('HTTP_CLIENT_IP')) $ipaddress = getenv('HTTP_CLIENT_IP'); else if(getenv('HTTP_X_FORWARDED_FOR')) $ipaddress = getenv('HTTP_X_FORWARDED_FOR'); else if(getenv('HTTP_X_FORWARDED')) $ipaddress = getenv('HTTP_X_FORWARDED'); else if(getenv('HTTP_FORWARDED_FOR')) $ipaddress = getenv('HTTP_FORWARDED_FOR'); else if(getenv('HTTP_FORWARDED'))   $ipaddress = getenv('HTTP_FORWARDED'); else if(getenv('REMOTE_ADDR')) $ipaddress = getenv('REMOTE_ADDR'); else $ipaddress = 'UNKNOWN'; return $ipaddress; } Method to fetch countryname & city  $id=trim('122.177.145.202'); $result  = array('country'=>'', 'city'=>''); $ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=...

Change in bootstrap datatable

How to change default sorting & disable sorting.   $('.dataTables-example').dataTable({ "order": [[ 7, "desc" ]], columnDefs: [   { orderable: false, "targets": -1 } ] }); Notes: 1.It will change default sorting to 7 column 2. Disable sorting form last column.

PHP XML handling

songs.xml <songs>     <song dateplayed="2011-07-24 19:40:26">         <title>I left my heart on Europa</title>         <artist>Ship of Nomads</artist>     </song>     <song dateplayed="2011-07-24 19:27:42">         <title>Oh Ganymede</title>         <artist>Beefachanga</artist>     </song>     <song dateplayed="2011-07-24 19:23:50">         <title>Kallichore</title>         <artist>Jewitt K. Sheppard</artist>     </song> </songs> eg <?php     $mysongs = simplexml_load_file('songs.xml');     echo "<ul id="songlist">n";     foreach ($mysongs as $songinfo):         $title=$songinfo->title;       ...

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 ...