Pages

Tuesday, 27 August 2013

Hyperlinks not working with jQuery mobile... Why?


Mobile jQuery processes each and every link and considers it as an ajax by default which will loads in the same page and not refresh the entire page. Links that point to other domains or that have rel="external", data-ajax="false" or target attributes will not be loaded with Ajax. Instead, these links will cause a full page refresh with no animated transition. Both attributes (rel="external" and data-ajax="false") have the same effect, but a different semantic meaning: rel="external" should be used when linking to another site or domain and data-ajax="false" is useful for simply opting a page within your own domain from being loaded via Ajax. Because of the security restrictions, the framework always opts links to external domains out of the Ajax behavior.

Let’s have a look at an example. I have many links on the page already and let’s say we have to popup using mobile jQuery. Adding rel="external" to each link is not possible as there are around thousand of links on my page. So using jQuery we can use the following code:

$(document).ready(function(){
    $("a").each(function(){
          $(this).attr("rel","external");
    });
}); 

The above code will apply rel attribute to all the links on the page. But if we want to 
implement a simple popup using the following code:
 
 <a href="#popupBasic" data-rel="popup">Open Popup</a>
 <div data-role="popup" id="popupBasic">
      <p>This is a completely basic popup, no options set.</p>
</div>
 
we will get issues as the “rel” attribute will also be applied to the link for popups too. 
So we can add a condition as shown below to avoid adding rel attribute to popup links:
 
$(document).ready(function(){
    $("a").each(function(){
        if($(this).attr("data-rel")!="popup") {
            $(this).attr("rel","external");
        }
    });
});

For more information click here
 
                                           

Sunday, 25 August 2013

INSERT … SELECT

INSERT [LOW_PRIORITY | HIGH_PRIORITY] [IGNORE]
       [INTO] tbl_name [(col_name,...)]
       SELECT ...
       [ ON DUPLICATE KEY UPDATE col_name=expr, ... ]
With INSERT ... SELECT, you can insert many rows into a table from one or many tables. This is a method to insert data very fast.

Example:
INSERT INTO employee (dept_id,emp_name)
       SELECT d.d_id as dept_id, p.name as emp_name
       FROM department as d 
       JOIN people as p 
       ON d.category_id = p.category_id
       WHERE p.category_id < 20;

In the above example we have fetched the department ids and the names from the select query and inserted into the employee table.

Saturday, 24 August 2013

INSERT

The INSERT ... VALUES and INSERT ... SET forms of the statements are used to insert rows which have values that are explicitly specified.

INSERT [IGNORE]
       [INTO] tbl_name [(col_name,...)]
       {VALUES | VALUE} ({expr | DEFAULT},...),(...),...
       [ ON DUPLICATE KEY UPDATE col_name=expr
       [, col_name=expr] ... ]

OR
INSERT [IGNORE]
       [INTO] tbl_name
       SET col_name={expr | DEFAULT}, ...
       [ ON DUPLICATE KEY UPDATE col_name=expr
       [, col_name=expr] ... ]

The INSERT ...SELECT form inserts rows selected from another table or tables.

INSERT [IGNORE]    
       [INTO] tbl_name [(col_name,...)]
       SELECT ...
       [ ON DUPLICATE KEY UPDATE  col_name=expr
       [, col_name=expr] ... ]

You can use REPLACE instead of INSERT to overwrite old rows.
The following statement
will create a row with the fields with its default values:
INSERT INTO tbl_name () VALUES();

If you want to insert a value[dependent on the previous
column] into a  column, then you can use
expressions.
INSERT INTO tbl_name (col1,col2) VALUES(20,col1*5); 
This will create a row with a value 20 in col1 and 100 (i.e. 20*5) in col2. 
NOTE: You cannot use the columns in the expressions before they have been assigned values.
SO THE FOLLOWING STATEMENT BECOMES ILLEAGAL:
INSERT INTO tbl_name (col1,col2) VALUES(col2*5,20);