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/

Friday, October 14, 2011

How to find the common values of two array, without using array_intersect


$array1 = array(’3′,’8′,’7′,’2′);
$array2 = array(’4′,’5′,’7′,’2′);
$length1=count($array1);
$length2=count($array2);
$common=array();
if ($length1 > $length2)
{
for ($i=0; $i<$length1; $i++)
{
if (in_array($array1[$i], $array2))
{
$common[]=$array1[$i];
}
}
}
else
{
for($i=0; $i<$length2; $i++)
{
if (in_array($array2[$i], $array1))
{
$common[]=$array2[$i];
}
}
}
print ‘
’;

print_r($common);
?>

category sub category program


mysql_connect("localhost","root","");
mysql_select_db("test");
class Categories
{
public function categories_tree($country_id='',$parent='0',$spacer='')
{
$sql = mysql_query("SELECT * FROM categories WHERE parent='$parent'");
$num = mysql_num_rows($sql);
$spacer .= '- ';
while ($row = mysql_fetch_array($sql))
{
if ($num == 0 || $row['parent']=='0')
{
$spacer = '';
}
echo $spacer.'‘.$row['name'].’
‘;
$this->categories_tree($country_id, $row['id'], $spacer);
}
}
}
$cat = new Categories();
$a = ”;
echo $cat->categories_tree(0, $a);
?>