Friday, 14 December 2012

Customize round funtion in php


function customizeRound($number){
    //this will convert 0.01 to 0.02 (But standard round function will not affect it as 1 in 0.01 is less than five)
    if($number > number_format($number,2)){
        $number=$number+ .01;
     }       return $number=number_format($number ,2);
 }

 //--usage--
 $number = 0.002;
 echo customizeRound($number);

Thursday, 18 October 2012

Parsing json data


<?php
$jsonData = '{"message-count":"1","messages":[{"to":"91XXXXXX","message-price":"0.00450000","status":"0","message-id":"010000000A37CCF1","remaining-balance":"1.91450000","network":"40402"}]}';
$obj = json_decode($jsonData, true);
echo "<br>message Count". $obj['message-count'];
echo "<br>message to". $obj['messages'][0]['to'];

/*
 $string='{"name":"John Adams"}';
// create object from string
$json_o=json_decode($string);
// create array from string
$json_a=json_decode($string,true);
 */
?>

Thursday, 17 May 2012

Multi Delete Query Using LEFT JOIN in Mysql

DELETE a.*, b.* FROM invoice_details a LEFT JOIN invoices b ON a.invoiceID=b.invoiceID WHERE a.rollover_by>0;

It will delete all the records from invoice_details and matching or available record from invoices(In this table record may be present or not).

Note: Have you notice the table name a.*, b.* used in selecting table for deletion. Yes you have to keep it in mind that you can use only alias table name for selection otherwise mysql will throw the error that "Table name does not exist".

Tuesday, 3 April 2012

Multiline title on mouse hover / Multiline button name



<input type="button" value="Really&#x00A;Tall&#x00A; Button" title="Really&#x00A;Tall&#x00A; Button">