Ajax Call Using Jquery

Syntex:
$.post(url?fistpost='+valueofirstpost+',{fistpost:"+valueofirstpost+"},
function($data){});

Note :
data : is the value from ur post url file

the fist parameter value be defined in the {} this is mandatory


Ex:
$.post(url?dateRangeValue="+ dateRangeValue +"&task=range", {dateRangeValue: ""+dateRangeValue+""}, function(data){
$('#divid').html(data); });

Query with Date -Examples

Selecting data using Dates:
Here is how we can select employees born in March.

select e_id, birth_date
from employee_per
where MONTH(birth_date) = 3;

+------+------------+
| e_id | birth_date |
+------+------------+
| 1 | 1972-03-16 |
| 16 | 1964-03-06 |
+------+------------+
2 rows in set (0.00 sec)


Alternatively, we can use month names instead of numbers.

select e_id, birth_date
from employee_per
where MONTHNAME(birth_date) = 'January';

+------+------------+
| e_id | birth_date |
+------+------------+
| 8 | 1975-01-12 |
| 19 | 1973-01-20 |
| 20 | 1968-01-25 |
+------+------------+
3 rows in set (0.00 sec)

Be careful when using month names as they are case sensitive. Thus, January will work but JANUARY will not!
Similarly, you can select employees born in a specific year or under specific dates.

select e_id, birth_date
from employee_per
where year(birth_date) = 1972;

+------+------------+
| e_id | birth_date |
+------+------------+
| 1 | 1972-03-16 |
| 4 | 1972-08-09 |
+------+------------+
2 rows in set (0.00 sec)


select e_id, birth_date
from employee_per
where DAYOFMONTH(birth_date) = 20;

+------+------------+
| e_id | birth_date |
+------+------------+
| 7 | 1966-08-20 |
| 19 | 1973-01-20 |
+------+------------+
2 rows in set (0.00 sec)


select e_id, birth_date
from employee_per where
MONTH(birth_date) = MONTH(CURRENT_DATE);

+------+------------+
| e_id | birth_date |
+------+------------+
| 8 | 1975-01-12 |
| 19 | 1973-01-20 |
| 20 | 1968-01-25 |
+------+------------+

3 rows in set (0.00 sec)

Mysql aggregate functions

SQL provides 5 aggregate functions. They are:
1). MIN(): Minimum value
2). MAX(): Maximum value
3). SUM(): The sum of values
4). AVG(): The average values
5). COUNT(): Counts the number of entries.

MYSQL Functions

Stored functions are similar to stored procedures: they are named program units that contain one or more MySQL statements.
They differ from procedures in the following ways:

  • The parameter list of a function may contain only IN parameters. OUT and INOUT parameters are not allowed. Specifying the IN keyword is neither required nor allowed.
  • The function itself must return a single value, whose type is defined in the header of the function.
  • Functions can be called from within SQL statements.
  • A function may not return a result set.
Syntex:

CREATE FUNCTION functionname (parametrs)
RETURNS type /* type->{STRING|INTEGER|REAL|DECIMAL} */
BEGIN
.......
RETURN value /* If u want to return*/
END;

Example :

CREATE FUNCTION get_volume(radius FLOAT)
RETURNS FLOAT DETERMINISTIC
BEGIN
DECLARE volume FLOAT;
SET volume = (4/5)*PI()*POW(radius,2);
RETURN volume;
END

Php :
// Connection
mysql_query($link,SELECT get_volume( 5.5));

In Command prompt >SELECT get_volume( 5.5)

Cursor in MYSQL

Cursor :


1 You need to declare a cursor for t1 table to go through its each and every record.
2 Open the cursor I have no idea about your tables in detail, if you have only one record in t2 table on base of t1 table, you can write a select statement to get that record or to check whether it is exists or not in t2 table but if you have multiple record then you need to write another cursor for t2 table to fetch each record and to get each an every record, and check whether record exist or not,if exist take another record from t1 else insert the t1 record into t2.
4 close cursor.
To use cursor in procedure there are four steps, declare, open,fetch and close.

example :

CREATE PROCEDURE procedure1(empno INTEGER) /* name */

BEGIN /* start of block */

DECLARE cur CURSOR FOR
// Use any one query from below
SELECT empid FROM employee WHERE empid=empno;
SELECT empid FROM employee WHERE ;
open curl;
emp_loop:LOOP
FETCH curl INTO employeeId;
END LOOP emp_loop;
CLOSE cur;
END /* end of block */


In PHP File:

$link = mysqli_connect('localhost','root', '', 'DATASERVICE_SAMPLE');

$result = mysqli_query($link,"CALL procedure1('1002')");

How to create Mysql Stored Procedure

Step-1
---------

Create Procedure First

Example
----------

USE DATASERVICE_SAMPLE ;
DROP PROCEDURE If EXISTS getEmployee ;
CREATE PROCEDURE getEmployee(empNo INTEGER) SELECT employeeNumber,lastName,firstName,email FROM Employees where employeeNumber = empNo ;
USE DATASERVICE_SAMPLE ;
DROP PROCEDURE If EXISTS getEmployee2 ;
CREATE PROCEDURE getEmployee2(empNo INTEGER) SELECT employeeNumber,lastName,firstName,email FROM Employees where employeeNumber = empNo ;

Step 1 : save above as the file in some path: $path(test.sql)

Step 2 : go to command prompt mysql -u root -p

Step 3 : run -> source $path (ex: source test.sql)



IN PHP FILE:


$link = mysqli_connect('localhost','root', '', 'DATASERVICE_SAMPLE');

$result = mysqli_query($link,"CALL getEmployee('1002')");
if( $result ){
while( $row = mysqli_fetch_array($result) ){
print_r($row );
}
}