Tuesday, 7 April 2015

jQuery Interview Questions and Answers for 2 Year experienced

jQuery Interview Questions and Answers for experienced


Question: How to select all the images of a div tag?
Use below of code snippets
$('div.mydiv').find('img');
OR
$('div.mydiv').children('img');


Question: How to get the value of selected checkbox?
Get the radio button value by button NAME
$("input[name='radioButtonName']:checked").val();
Get the radio button value by button CLASS
$('.radioButtonClass:checked').val();


Question: How to get the value of selected checkbox?
Get the checkbox value by NAME
$("input[name='checkboxName']:checked").val();
Get the checkbox value by CLASS
$('.chekboxClass:checked').val();


Question: How to check, If element exist OR not?
Check the existence of element By ID
if($('#mydivId').length )){
    //console.log('Element exist);
}else{
//console.log('Element does exist);
} 

Check the existence of element By CLASS
if($('.mydivClass').length )){
    //console.log('Element exist);
}else{
//console.log('Element does exist);
} 


Question: How to select elements which have two classes?
Just write the selectors together without spaces, to select the elements having two classes?
myDivClass1$('#mydivId.myDivClass1.c.myDivClass2').val();
It will get all the elements, which have div with mydivId (ID), div with myDivClass1 (Class) and div with myDivClass2(class).


Question: How to disabled a button?
Disabled the button by ID
$("input#myDivId").prop('disabled', true);

Disabled the button by CLASS
$("input#myDivClass").prop('disabled', true);


Question: How to change the anchor tag's href?
Change the href value by ID
$("a#myATagId").attr("href", "http://www.web-technology-experts-notes.in/p/sitemap.html");
Change the href value by CLASS
$("a.myATagClass").attr("href", "http://www.web-technology-experts-notes.in/p/sitemap.html")


Question: How to set the cookie with jQuery?
jQuery core do not have cookie functions. For this, we can include jQuery cookie plugins and its really make the cookie handling very easy.

Download Cookie plugin from Below URLs.
http://plugins.jquery.com/cookie/
Set the cookie using plugin.
$.cookie("cookieName", "cookieValue", { path: '/', expires: 7 }); 

Get a cookie using plugin.
$.cookie("cookieName");

Delete the cookie.
$.removeCookie("cookieName");



Question: How to update the HTML of container?
Update the container with using ID
$('div#myDivId').html('this is new updated html tag.');

Update the container with using class
$('div.myDivClass').html('this is new updated html tag.');



Question: How to get the HTML of container?
Get the container's value with using ID
$('div#myDivId').html();

Get the container's value with using class
$('div.myDivClass').html();



Question: How to distinguish between left and right mouse click with jQuery on paragraph tag?
$('p#myParagraphId').mousedown(function(event) {
    switch (event.which) {
        case 1:
            //alert('Left Mouse.');
            break;
        case 2:
            //alert('Middle Mouse .');
            break;
        case 3:
           // alert('Right Mouse .');
            break;
        default:
            //alert('Else click');
    }
});


Question: How to get the hash values of URL?
As we know, we can't get the hash values with using PHP. but we can get the hash values with javaScript.
if(window.location.hash) {
  // hash values
}



Question: How to change the image source using jQuery?
Change the image source with using ID
$('img#myImageId').attr('src','http://mydomain.com/newimage.png');

Change the image source with using Class
$('img.myImageClass').attr('src','http://mydomain.com/newimage.png');




Monday, 6 April 2015

MySQL Interview Questions and Answers for Experienced

MySQL Interview Questions and Answers for Experienced

Question: Can I concatenate multiple MySQL rows into one field?
use GROUP_CONCAT function
For Example
SELECT group_concat( city, '--' ) AS all_city FROM `cities`WHERE 1 LIMIT 0 , 30
Output:
New York--,London--,Chicago--,Frankfurt--,Paris--



Question: How to output MySQL query results in csv format?
Its quite simple.
  • First get the queries with column which you want to write.
  • Seconds Use OUTFILE (filename with location), FIELDS TERMINATED BY (field separator), ENCLOSED BY and LINES TERMINATED (Line Separator) BY for format.

SELECT city from cities INTO OUTFILE 'city.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'



Question: How do you set a default value for a MySQL Datetime column?
You can add default time, when data type is timestamp.
See Example:
CREATE TABLE `mytable` (`id` INT NULL ,`created_at` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL ,PRIMARY KEY ( `id` ) ) ENGINE = InnoDB;



Question: Difference between utf8_general_ci and utf8_unicode_ci?
utf8_unicode_ci is more accurately as compare to utf8_general_ci.
utf8_unicode_ci is support more lanaguages as compare to utf8_general_ci.
utf8_general_ci is faster at comparisons and sorting as compare to utf8_general_ci.



Question: How to make multiple column as unique?
use UNIQUE Constraint for creating multiple column as unique.
For Example
ALTER TABLE `mytable` ADD UNIQUE `unique_index`(`user`, `email`, `address`);



Question: How to find duplicate email records in MySQL?
SELECT u1.first_name, u1.last_name, u1.email FROM users as u1
INNER JOIN (
    SELECT email FROM users GROUP BY email HAVING count(id) > 1
    ) u2 ON u1.email = u2.email;



Question: How can you reset AUTO_INCREMENT for user table?
ALTER TABLE users AUTO_INCREMENT = 1



Question: How to make duplicate table in MySQL?
CREATE TABLE users_new LIKE users; //Copy the structure
INSERT users_new SELECT * FROM users; //copy the table rows



Question: How to Group by multiple column(i.e email and ssn)?
select * from users group by concat(email,"-",ssn);


Question: MySQL: @variable vs. variable. Whats the difference?
@variable are user-defined variable used in statements which retain its values during the same session is active.
variable are procedure variable used in store procedure only. It never retain its value. Each time store procedure called its value set to null automatic.



Question: What is query to show list of Stored Procedures?
SHOW PROCEDURE STATUS;


Question: What is query to show list of functions?
SHOW FUNCTION STATUS;


Question: How to check last queries executed on MySQL?
check mysql.log


Question: How to get the sizes of the tables of a mysql database?
SELECT table_name AS "Table", 
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB" 
FROM information_schema.TABLES 
WHERE table_schema = "geob2cdev" ORDER BY (data_length + index_length) DESC 


Question: How to check specific table details?
SHOW TABLE STATUS WHERE Name = 'users';


Question: How to rename a table?
RENAME TABLE `mytable` TO `geob2cdev`.`mytable1` ;


Question: How to rename a column?
ALTER TABLE `mytable1` CHANGE `created_at` `created_at1` TIMESTAMP; 

Question: How to insert current datetime in column?
Use Now() function
INSERT INTO `users` (`id`,`name`,create_time) VALUES (NULL,  'this is test\'s message',now());




Question: Can we have multiple order by in single Query?
Yes, We can have
select * from users where upper(name) = upper('Hello') order by name asc, id desc




Question: How to remove stored PROCEDURE?
DROP PROCEDURE storedProcedureName



Question: How to remove stored PROCEDURE if exist?
DROP PROCEDURE IF EXISTS storedProcedureName