Tuesday, August 23, 2011

Funtion of Sorting an Array using Php

$arr = array(1,7,6,8,4,5,2);

function sg_array_sort($arr) {
    for($i=1;$i      for($j=$i-1;$j>=0;$j--) {   
         if($arr[$i] < $arr[$j]) {
            $temp = $arr[$i];
            $arr[$i]= $arr[$j];
            $arr[$j] = $temp;
            $i = $j;

$sort_arr =  sg_array_sort($arr);

Many-to-many MySql relation: how to retrieve all related entries in one query?

Suppose there are 3 Table 1) Products , 2)Category & 3)Pro_Cat :- Many to Many RelationShip B/w Products & Category Table :-

1) Products Table :-                                  


2) Category Table :-


3) Product_Category Many into Many Relationship Table :-


Result Query :-

  GROUP_CONCAT(category.category_name) AS category_name
FROM product,category,pro_cat
Where product.product_id = pro_cat.product_id
and category.category_id = pro_cat.category_id
GROUP BY product.product_id;

Result :-

Mobile ,Usb

Tuesday, July 26, 2011

The Flipkart Story (Case Study)

It’s been about a year since Flipkart started moving from being a pure bookstore to selling mobiles/DVDs etc. Then we had cribbed about a possible brand dilution and investor pressure. Probably we were never sure about the bigger picture. Since then, Flipkart went for a major brand makeover, making it look more ‘upmarket’. There has been large newspaper ads, TVCs and a lot of web ads. But unlike other eCommerce companies the inorganic marketing kicked in only when the product was strong.
Flipkart already had a proven model execution with books and extending to other verticals did not need infrastructural changes. Flipkart’s real achievement has been in solving the pain points in Indian eCommerce that most well funded players are still complaining  about.
Here are some of the things that Flipkart has done well in solving each of these problems.

1. Discoverability:

It is the case with any venture on the web, “How does the customer find us?” Answer: Organically!
Flipkart has been the “baap” of SEO. This has been the most important contributor to their success. I say this, because only when you see people coming to you, you get encouraged to deliver more and keep adding. There is no fun (motivation) in adding features to a product that no one is using.
Though from what I had noticed, SEO did not come the straight way. There were particularly 2 things that are worth mentioning.
a. Yahoo News: Until last year Flipkart had a feed of Yahoo News on its product pages. From what I understand of SEO, this is to increase the keyword density and introduce ‘original’ content on the page, as the product description across all books sites is same. This was removed later as it was violating the Yahoo’s ToS on using the service for a commercial site. Check the Waybackmachine here. I loved the risk they took for this.
b. We Do Not Sell Used Books: This one is my favorite. If you check the Waybackmachine in the last line you will notice the following text.

  • We DO NOT sell old books or used books. All the books listed at Flipkart.com are new books.

  • The books listed at Flipkart.com are NOT available for free download in ebook or PDF format.

  • The magic of this text is that if you search for free ebook or pdf download” you would always get Flipkart among the top results. These are very popular search queries and Flipkart had nothing to do with it but still they cashed in. This was also the time when Flipkart had Adsense embedded. People would come to the site, see nothing like a “PDF download” button, and then see an ad for PDF download and click. This meant more revenue for Flipkart. I have done this atleast twice myself. Given that the margin on books are very small after the discount, Flipkart was probably earning more by saying what they did not do than by doing what they actually were suppose to do.

    2. Payments:

    No credit card/netbanking, fear to transact online, repeat transaction failures, no access to web – these are the common problems with online payments. What Flipkart is doing to overcome these?
    From what I last counted, Flipkart had atleast 4 different Payment Gateways integrated. They introduced Cash-on-Delivery. Then they are also doing order on phone. Payment via DD/Cheque is also accepted.
    2 basic things that they are currently doing that takes little tech. effort but quite some product management ‘will’:
    a. Auto redirection to banking site: Unlike most other ecommerce sites, Flipkart never lands you on CCavenue page, you are auto redirected to the banks page where the info is required to be filled. Flipkart by-passes 1 unnecessary page by passing the required parameters directly to CCavenue and not through a user interface.
    b. Banks Status: Flipkart maintains its own real time status if the bank’s netbanking is working or not. So there are no surprises after you have chosen the bank and then go to the netbanking page.
    And if you think Flipkart gets very good rates from Payment Gateways, not really. Atleast 1 big PG that I am aware of charges quite high rates to Flipkart, atleast 40-50% more than to lesser known players.

    3. Inventory:

    I come from a traditional business family where we believe in selling what we have. The world of eCommerce really amazes me when I see the players keeping a standard list of products and then go out procuring it only when there is an order placed. Imagine if you go to a brick & mortar shop and after billing the manager sends a boy to a nearby store to get the goods. This is where the problem starts. There is no inventory on their end and there is no live status of inventory from their supplier. Remember The Alchemist, “Never Promise something that you don’t have“.
    After placing an order, they would keep looking for the product at multiple places. After a week you might get a call saying that either the product is not available and we will do a ‘favor’ by refunding your money or if the product is there, it is not the color/size that you asked for.
    Flipkart was no different in 2009, a couple my friends used to get similar calls after days of ordering. But for the last 1 year atleast Flipkart maintains its own inventory(or atleast it seems so). They are selling what they have. From pure hearsay, Flipkart is taking up a big warehouse in Bangalore and is in talks for one in NCR as well. One of the few companies that is using the funding to build a business and not spend it like a FMCG company on ads.

    4. Delivery:

    I have dealt with courier companies in my last startup and am quite aware of the ‘fcukall’ standards they have. Most similar looking envelopes are never delivered thinking that it is a marketing package and no one would track it. They would be willing to bargain on rates but would never say anything about the service. Paying a premium may not solve the problem always.
    Flipkart is exploiting this problem as a cashable need gap and building its own delivery backendFlipkart is seen delivering through their own delivery boys in Bangalore and at times within 12hrs from order.
    Flipkart has started putting fliers in newspapers in Bangalore with a product listing, call-to-order phone number and a promise of delivering ‘tomorrow’. This means more discoverability, no payment problem and no delivery delay. The way it is actually suppose to be.
    From what I heard from multiple sources, Flipkart is looking to build its own courier company. The recent $20Mn funding from Tiger Global was only part of a larger sum they are known to be raising. Flipkart is looking to raise $100Mn at a valuation of $200Mn.
    Recently, Flipkart has started selling everything from cameras, laptops to gaming consoles to personal and health care electronic products. There are major talks about Amazon acquiring Flipkart but it would only make sense to grow it bigger and better from here. A handover wouldn’t see the same product management ‘will’.
    Flipkart is a story that is come from smart work and an ‘it is possible’ attitude. There is a need to for a couple of more stories like these and there would be no cribbing about Indian eCommerce not working.

    Thursday, May 26, 2011

    MySql FEDERATED storage engine :Data to be accessed from a remote MySQL database on a local server without using replication or cluster technology

    MySql FEDERATED storage engine :-

    Than enable you to create table into local server Database and allow access data from Remote Server Database without using replication or cluster technology.

    Use FEDERATED Tables :-

    First, you must have a table on the remote server that you want to access by using a FEDERATED table. Suppose that the remote table is in the federated database and is defined like this:

    CREATE TABLE test_table (
        id     INT(20) NOT NULL AUTO_INCREMENT,
        name   VARCHAR(32) NOT NULL DEFAULT '',
        other  INT(20) NOT NULL DEFAULT '0',
        PRIMARY KEY  (id),
        INDEX name (name),
        INDEX other_key (other)
    The example uses a MyISAM table, but the table       could use any storage engine.     
    Next, create a FEDERATED table on the local server for accessing the remote table:

    CREATE TABLE federated_table (
        id     INT(20) NOT NULL AUTO_INCREMENT,
        name   VARCHAR(32) NOT NULL DEFAULT '',
        other  INT(20) NOT NULL DEFAULT '0',
        PRIMARY KEY  (id),
        INDEX name (name),
        INDEX other_key (other)
    (Before MySQL 5.0.13, use COMMENT rather than       CONNECTION.)

    Check FEDERATED Engine enable or not in database :-

    mysql> show engines;
    | Engine     | Support | 
    | ndbcluster | NO      | 
    | MRG_MYISAM | YES     | 
    | BLACKHOLE  | YES     | 
    | CSV        | YES     | 
    | MEMORY     | YES     | 
    | FEDERATED  | NO      | 
    | ARCHIVE    | YES     | 
    | InnoDB     | YES     | 
    | MyISAM     | DEFAULT |
    For Enable federated Engines into MYSQL :-
    Add Below Line into my.ini or my.cnf :-
    Then Restart MySQL Server.

    MySql Error Too many connections

    The default setting for max_connections is 100. You can see what the current setting is by running the following SQL command from the MySQL command line tool, phpMyAdmin, or a similar tool:

    show variables like "max_connections";
    This will return a resultset like this, showing you what your current max connections setting is:

    | Variable_name   | Value |
    | max_connections | 100   |

    To update the max_connections setting in MySQL :-

    You can change the setting to e.g. 200 or more that depend upon ur server RAM size by issuing the following command without having to restart the MySQL server (obviously it will only work if the user you are logged in as has sufficient permissions to do this) ,no need to restart server:

    set global max_connections = 200;
    This will take effect immediately, but will be forgotten the next time MySQL is restarted. To make the change permanent you need to edit the my.cnf configuration file. On CentOS, RedHat and similar distributions this is at /etc/my.cnf; other distros will store it elsewhere.

    Under the [mysqld] section add the following setting:

    max_connections = 200
    Now when you restart MySQL the next time it will use this setting instead of the default.

    Note that increasing the number of connections that can be made will increase the potential amount of RAM required for MySQL to run. Increase the max_connections setting with caution!

    Tuesday, May 10, 2011

    Good Blog on tagg.in

       I want to share some good blog on tagg.in ( Fast & free Sms blogging Site) .
       Where you can join by sending SMS Blog_Name to 92234 92234 (Normal Sms Cost / Free if you have free SMS Plan) or 560700 (cost Rs 2-3) or you can create your blog by sending SMS Create Your_Blog_Name to 92234 92234 or 560700 or you also login/Signup on http://www,tagg.in .Then you send & receive free Sms to your follower.

    For Free IPL News send SMS Join Blog_name to 92234 92234 or 560700:-
      1)  FULL_SCORE
      2) ICCnet
      3) IPL_CRI
      5) SUNSPORTS

    for Jokes :-
    2) Ruchi
    3) HasiMazak

    for News :-
    2) NEWSalerts
    3) GP-NEWS
    4) 100RBGoyal

    for Health :-
    and much more free Sms blog.