Monday, 8 August 2016

Find out nth order salary in MySQL

To find out the nth highest salary from employee table :
SYNTAX:

SELECT * from employee emp WHERE (n) = (SELECT COUNT(emp2.salary) FROM employee emp2 WHERE emp2.salary >= emp.salary)
where n is the number of salary which you want.

OR

To Find the 2nd Highest Salary in following ways



SELECT name, salary FROM employee where salary NOT IN (SELECT MAX(salary) from employee)

SELECT MAX(salary) FROM employee where salary NOT IN (SELECT MAX(salary) from employee)
SELECT DISTINCT salary FROM employee ORDER BY salary DESC LIMIT 1,1;

Send Mail via PHP

Send an Email via PHP
Step 1: Create the form for an Email



<form action="mail_send.php" method="post" name="email">
<table width="354" height="279" >
<tr><td>To:</td><td><input type="email" name="to" value="" />
</td></tr>
<tr><td>From Name:</td><td><input type="text" name="name" value="" />
</td></tr>
<tr><td>Subject:</td><td><input type="subject" name="subject" value="" />
</td></tr>
<tr><td>From Email:</td><td><input type="email" name="femail" value="" />
</td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value="SEND" />
</td></tr>
<tr><td>Message:</td><td><textarea cols="20" name="message" rows="8">
</textarea></td>
</tr>
</table>
</form>
Step 2: Write the php script for email


<?php 
if(isset($_POST[femail])){
    $to = $_POST["to"];
    $femail = $_POST["femail"];
    $name = $_POST["name"];
    $subject = $_POST["message"];
    $message = wordwrap ($message, 70);
    mail($to, $subject, $message, "From: $femail\n");
    echo "Thank you for sending a mail";
}else{
    echo 'mail not send..!!';
}
?>


Wednesday, 3 August 2016

Make dropdown as a required field in HTML5

If you want to make <select> field as a required field then you have to do like this
<select name="" required x-moz-errormessage="Please Select the Field">
<option value="">Select the Field</option>
<option value="One">One</option>
<option value="Two">Two</option>
</select>

INNER JOIN of two tables

if you have two tables like product and product_description  and you want the inner join of these tables then the query will be like this:
select product.model, product_description.name, product.price, product.weight, 
product_description.description from product INNER JOIN product_description on
product.product_id=product_description.product_id

Tuesday, 2 August 2016

ADD Foreign Key in existing Table

How to add Foreign Key in existing table
if you want to add any column as a foreign key in your existing table then you have to write following MySQL query for that
Syntax:
ALTER TABLE tablename ADD CONSTRAINT FOREIGN KEY column_name REFERENCES ref_table_name(column_name)
if you want to add multiple column as a foreign key in the same table then you have to write the following MySQL query:
Syntax:
ALTER TABLE tablename 
ADD CONSTRAINT FOREIGN KEY column_name REFERENCES ref_table_name(column_name)
ADD CONSTRAINT FOREIGN KEY column_name REFERENCES ref_table_name(column_name)
ADD CONSTRAINT FOREIGN KEY column_name REFERENCES ref_table_name(column_name)