. Rising Code Challenges Skip to main content

Posts

Magic function library for Codeigniter like CakePHP

CodeIgniter is a powerful PHP framework with a very small footprint, and very useful for website. Today I am going to introduce you the Magic function for CI like CakePHP. What is Magic Functions As the name "Magic function" there are some magic with its library which you can download from here . By using this library, you don't need to do define any function in your models all functions which you want it has already created just like magic. There is a library Magic.php which convert your function into Database Query and produce result as you want. Clone the Magic.php in your local directory and place it into application/library in your CI project. Now set this library in application/config/autoload.php . so don't need to load in every controller. $autoload['library'] = array('Magic'); Now your magic library is ready to use with $this->magic instance. Structure: $this->magic Instance of library. ->tableName set tabl...

What is the difference between an interface and abstract class

This is an extremely common interview question. It's surprising since an abstract class is rarely used in solutions compared to other things. Many junior developers make the mistake of thinking of interfaces, abstract and concrete classes as slight variations of the same thing, and choose one of them purely on technical grounds: Do I need multiple inheritance? Do I need some place to put common methods? Do I need to bother with something other than just a concrete class? So here is a clear difference and uses of Interface and Abstract class. The key technical differences between an abstract class and an interface are: Abstract classes can have constants, members, method stubs (methods without a body) and defined methods , whereas interfaces can only have constants and methods stubs . Methods and members of an abstract class can be defined with any visibility , whereas all methods of an interface must be defined as public (they are defined public by default). When inhe...

How to reset an array keys in php

In this post we will discuss to reset an array after add or delete an index. If there are an array $a $a = array( 0 => 3, 1 => 5, 2 => 7, 3 => 9, 4 => 0 ); Now we updates this array and delete index 2 , so the new array is - unset($a[2]); $a = array( 0 => 3, 1 => 5, 3 => 9, 4 => 0 ); Index 2 has been removed from array and we have to re-arrange all indexes of array. So its not a big task. Just a simple step and array will arrange form index 0 to 3. Use the predefined array function array_values and the array indexes will be reset. $a = array_values($a); $a = array( 0 => 3, 1 => 5, 2 => 9, 3 => 0 ); This was a simple array. If we have a multi-dimensional array, Then !!. Nothing to worry about multi-dimensional, PHP have all tricky solutions :) $reset_array = array_map('array_values', $arr); To reset multidimensional array use array_map . Here $arr is a multidimensional array with different...

How works ng-hide and ng-show in angular js

Angualrjs is the most popular js framework today. This is widely used in develop Mobile apps by using phonegap.  And also angular js used  in website. AngularJS lets you extend HTML vocabulary for your application. The resulting environment is extraordinarily expressive, readable, and quick to develop. ng-show The ngShow directive shows or hides the given HTML element based on the expression provided to the ngShow attribute. The element is shown or hidden by removing or adding the .ng- hide CSS class onto the element. The .ng-hide CSS class is predefined in AngularJS and sets the display style to none (using an !important flag). For CSP mode please add angular-csp.css to your html file. ng-hide The ngHide directive shows or hides the given HTML element based on the expression provided to the ngHide attribute. The element is shown or hidden by removing or adding the ng-hide CSS class onto the element. The .ng-hide CSS class is predefined in AngularJS and sets the display style to no...

Hide show HTML element by javascript

Hide show any element on a HTML page is vary common thing for websites. For Hide and Show elements Jquery is the most common and reliable framework. But There is some performance issue by jquery, so Javascript is the best solution for Hide and show any element on a web page. Sometimes JQuery isn't necessary; if this is the only thing you need to do on a page, the overhead of loading the library far outweighs the need to write concise JavaScript. It seems that hide() , show() and jquery visibility methods in general are not a good option in terms of performance. Hide an element by id  in Javascript: [code language="js"] document.getElementById("id").style.display = "none"; [/code] Hide an element  by id  in jquery: [code language="js"] $("#id").hide(); [/code] Hide an element by class in javascript : [code language="js"] document.getElementsByClassName("class")[0].style.display = "none"; [/code] Hide el...

How to manage multi level categories in PHP and MySQL

For the websites it is common to manage articles, products and much more thing by categories. And these categories have child categories and these child also have child and so in. So this article will show you that how to manage the Multi-level categories tree in PHP and MySql . First of all we need a Database table to store all categories. CREATE TABLE `tblcategory` ( `id` int(10) NOT NULL auto_increment, `pid` int(10) NOT NULL default '0', `title` varchar(255) NOT NULL, PRIMARY KEY (`id`) ); Multilevel categories tree in database table. Now time to get list of all categories with parent and their child, grand child and so on. There are two way to find all categories. 1. First solution that all knows, Recursion   In Recursion, first get all main parents categories and then start a loop and fetch all subcategories with their parent id's. function showCategories($cat_id = 0, $dashes = ''){ $dashes .= '--'; ...

How to handle duplicate data in MySql

This is very common problem in huge database to handle the duplicate data. Tables or result sets sometimes contain duplicate records. Sometimes, it is allowed but sometimes it is required to stop duplicate records. Sometimes, it is required to identify duplicate records and remove them from the table. This chapter will describe how to prevent duplicate records occurring in a table and how to remove already existing duplicate records. Check Duplicate data in table SELECT `col_name`, COUNT(*) as `record_find` FROM table GROUP BY col_name HAVING `record_find` > 1; Above query result will show the column name and number of time of record find in database table. Delete all duplicate records 1) If you want to keep the row with the lowest id value: DELETE n1 FROM names n1, names n2 WHERE n1.id > n2.id AND n1.name = n2.name 2) If you want to keep the row with the highest id value: DELETE n1 FROM names n1, names n2 WHERE n1.id < n2.id AND n1.name = n2.name I used this method in MySQL...