Friday, October 21, 2011

Remove duplicate record in multi dimensional array

<?
error_reporting(1);
$arr1=Array(
    459 => Array
        (
            "maxScore" => 1.7873402,
            "score" => 1.3271129,
            "book_id" => 260,
            "book_part_autoid" => 4161,         
        ),460=> Array(
            "maxScore" => 1.7873402,
            "score" => 1.3268949,
            "book_id" => 260,
            "book_part_autoid" => 4161,           
        ),

    461 => Array
        (
            "maxScore" => 1.7873402,
            "score" => 1.3268949,
            "book_id" => 260,
            "book_part_autoid" => 4164,

        ),462 => Array
        (
            "maxScore" => 1.7873402,
            "score" => 1.32654,
            "book_id" => 260,
            "book_part_autoid" => 4198,
           
        )

);



foreach($arr1 as $key=>$val)
{

         if(!isset($result[$val['book_part_autoid']]))
{
               $result[$val['book_part_autoid']]=$val;

}


}


echo "<pre>";
print_r($result);
echo "</pre>";

?>

Monday, October 17, 2011

YesterDay In PHP

<?php
$m=date('m');
$d=date('d');
$y=date('Y');
echo $todaydate=date('Y-m-d');
$yday=date("Y-m-d", mktime(0, 0, 0,$m,$d-1,$y));
echo "<br>";
echo $yday;
?>

Friday, October 14, 2011

Using Join Compare two tables

select * from table1 Left join table2 ON table1.name=table2.name where table2.name IS NULL

Compare two tables in mysql

select * from table1 where name NOT IN (select name from table2)

Character count Query

SELECT a.charcount, count( a.charcount )
FROM (

SELECT notedescription, CHARACTER_LENGTH( notedescription ) AS charcount
FROM iplat_user_notes
) AS a
GROUP BY a.charcount
ORDER BY count( a.charcount ) DESC