Thursday, November 17, 2016

Copy Selected fields from table2 to table1


If we want to set employeeCode in employeeMaster1 from employeeMaster2 for corresponding employeeId 

A join:

UPDATE employeeMaster1 AS t1
  INNER JOIN employeeMaster2 AS t2 ON t1.employeeId = t2.employeeId

SET t1.employeeCode = t2.employeeCode

By Using left join:

UPDATE employeeMaster1 AS t1
  LEFT JOIN employeeMaster2 AS t2 ON t1.employeeId = t2.employeeId
SET t1.employeeCode = t2.employeeCode


A subquery:

UPDATE employeeMaster1
SET employeeCode = (
  SELECT employeeCode
  FROM employeeMaster2
  WHERE employeeId = employeeMaster1.employeeId

)

Saturday, April 23, 2016

Upload Image Using JQuery. Insert Into Database.


How To insert image into Database.
Please follow the below Steps:-

(1) Create a database

   CREATE TABLE IF NOT EXISTS `userinfo` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(222) NOT NULL,
`picture` varchar(222) NOT NULL,
`createdDateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

(2) create a folder structure inside your web application folder.

     upload

(3) Create a file with the name index.php

a. Create HTML form
name,userImage
b. load jquery "https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"

c. use id "uploadTopic" for form.

d. Create DIV as follows


e. Place following code at the bottom


4. Create a file upload.php and place the following code:-

mysql_connect("localhost","root","root");
mysql_select_db("test");

if(!empty($_POST))
{
  $name = $_POST['name'];
  if(isset($_FILES['userImage']['name']) && $_FILES['userImage']['name']!='')
  {
 $desired_path = 'upload/';

 $rand=rand(0,999);
 $desired_file_name = $rand.'_'.str_replace(' ','_',strtolower($_FILES['userImage']['name']));

 move_uploaded_file($_FILES['userImage']['tmp_name'], $desired_path . $desired_file_name);
  }

$query_insert="INSERT INTO userInfo SET name = '".$name."',picture='".$desired_file_name."'";
mysql_query($query_insert);
}
?>

Thursday, March 1, 2012

10 Second Highest Salary of Employee


SELECT * FROM employee E1
WHERE 1 = ( SELECT COUNT( DISTINCT salary )
 FROM employee E2
 WHERE E1.salary < E2.salary
  )
   LIMIT 0,10

Friday, February 17, 2012

Sorting a Multi-Dimensional Array with PHP


//an array of some songs I like
$employee =  array(
  '1' => array('name'=>'Hanzala Subhani', 'job_title'=>'Software Developer'),
  '2' => array('name'=>'Safdar Subhani', 'job_title'=>'Software Developer'),
  '3' => array('name'=>'Shamsh Jawed', 'job_title' =>'Manager')
 );

function sort_employee($a,$subkey) {
 foreach($a as $k=>$v) {
  $b[$k] = strtolower($v[$subkey]);
 }
 asort($b);
 foreach($b as $key=>$val) {
  $c[] = $a[$key];
 }
 return $c;
}


$employee = sort_employee($employee,'artist'); 
print_r($employee);

Thursday, February 2, 2012

Redierct url

$url = 'http://webmicrosystems.com?p=1';
$headers = get_headers($url,1);
echo $headers["Location"];

Thursday, January 19, 2012

Wednesday, January 18, 2012

SIMPLE CRUD – CODEIGNITER

For this Please follow this link
http://henrihnr.wordpress.com/2009/04/26/simple-crud-application/