Wednesday, July 17, 2013

`number_to_string api

DELIMITER $$
CREATE FUNCTION `number_to_string`(n INT) RETURNS varchar(100)
BEGIN
    -- This function returns the string representation of a number.
    -- It's just an example... I'll restrict it to hundreds, but
    -- it can be extended easily.
    -- The idea is:
    --      For each digit you need a position,
    --      For each position, you assign a string
    declare ans varchar(100);
    declare dig1, dig2, dig3 int; -- (one variable per digit)

    set ans = '';

    set dig3 = floor(n / 100);
    set dig2 = floor(n / 10) - dig3*10;
    set dig1 = n - (dig3*100 + dig2*10);

    if dig3 > 0 then
        case
            when dig3=1 then set ans=concat(ans, 'one hundred');
            when dig3=2 then set ans=concat(ans, 'two hundred');
            when dig3=3 then set ans=concat(ans, 'three hundred');
            when dig3=4 then set ans=concat(ans, 'four hundred');
            when dig3=5 then set ans=concat(ans, 'five hundred');
            when dig3=6 then set ans=concat(ans, 'six hundred');
            when dig3=7 then set ans=concat(ans, 'seven hundred');
            when dig3=8 then set ans=concat(ans, 'eight hundred');
            when dig3=9 then set ans=concat(ans, 'nine hundred');
            else set ans = ans;
        end case;
    end if;

    if dig2 = 1 then
        case
            when (dig2*10 + dig1) = 10 then set ans=concat(ans,' ten');
            when (dig2*10 + dig1) = 11 then set ans=concat(ans,' eleven');
            when (dig2*10 + dig1) = 12 then set ans=concat(ans,' twelve');
            when (dig2*10 + dig1) = 13 then set ans=concat(ans,' thirteen');
            when (dig2*10 + dig1) = 14 then set ans=concat(ans,' fourteen');
            when (dig2*10 + dig1) = 15 then set ans=concat(ans,' fifteen');
            when (dig2*10 + dig1) = 16 then set ans=concat(ans,' sixteen');
            when (dig2*10 + dig1) = 17 then set ans=concat(ans,' seventeen');
            when (dig2*10 + dig1) = 18 then set ans=concat(ans,' eighteen');
            when (dig2*10 + dig1) = 19 then set ans=concat(ans,' nineteen');
            else set ans=ans;
        end case;
    else
        if dig2 > 0 then
            case
                when dig2=2 then set ans=concat(ans, ' twenty');
                when dig2=3 then set ans=concat(ans, ' thirty');
                when dig2=4 then set ans=concat(ans, ' fourty');
                when dig2=5 then set ans=concat(ans, ' fifty');
                when dig2=6 then set ans=concat(ans, ' sixty');
                when dig2=7 then set ans=concat(ans, ' seventy');
                when dig2=8 then set ans=concat(ans, ' eighty');
                when dig2=9 then set ans=concat(ans, ' ninety');
                else set ans=ans;
            end case;
        end if;
        if dig1 > 0 then
            case
                when dig1=1 then set ans=concat(ans, ' one');
                when dig1=2 then set ans=concat(ans, ' two');
                when dig1=3 then set ans=concat(ans, ' three');
                when dig1=4 then set ans=concat(ans, ' four');
                when dig1=5 then set ans=concat(ans, ' five');
                when dig1=6 then set ans=concat(ans, ' six');
                when dig1=7 then set ans=concat(ans, ' seven');
                when dig1=8 then set ans=concat(ans, ' eight');
                when dig1=9 then set ans=concat(ans, ' nine');
                else set ans=ans;
            end case;
        end if;
    end if;

    return trim(ans);
END$$

DELIMITER ;

--------------------
after executing query
test-: SELECT number_to_string( 150 ); 

count special Character (how many time occur) and set inside value in an array.

<?php 

$mystring = "my ,name ,is ,sudhir ,kumar";

$n = strpos($mystring, ',');

//echo substr($mystring, 2, $n)

$myArray = explode(',' ,$mystring);

$num=substr_count($mystring, ',');

for($i=0;$i<=$num;$i++)

{

echo $myArray[$i];

}

?>

Saturday, July 13, 2013

EVEN AND ODD RULES

tr:nth-child(even) {background: #CCC}
tr:nth-child(odd) {background: #FFF}

li:nth-child(5n+3) {font-weight: bold}

col:first-child {background: #FF0}
col:nth-child(2n+3) {background: #CCC}

Friday, July 12, 2013

Add cart item in session aaray and delete one session variable from session key

1. you have to add item in session array.
code-:
$_SESSION['challan'][] =$challan_nmber;
here $_SESSION['challan'][] is session and session_nmbr is value;
---------------------------------------------------------------------------
2. fetch_the_whole session_data
                foreach ($_SESSION['challan'] as $key=>$value)
{
echo '<b>_'.$value.'</b>';
}
---------------------------------------------------------------------------
3. unset one variable
                      $key=array_search($challan_nmber,$_SESSION['challan']);
unset($_SESSION['challan'][$key]);

here $key will search challan_nmber and will match with $_SESSION['challan']); if found it will unset.

------------------------------------ *** Whole code ***  -------------------------------------------------
if(isset($_POST['add_to_bill']))
{
session_start();
$company_code=strip_tags($_POST['add_to_bill']);
$challan_nmber=strip_tags($_POST['challan_nmbr']);
$responce_code=strip_tags($_POST['responce_code']);

if($responce_code==1)
{
$query1=mysql_query("update table_name set status=4 where bill_number='$challan_nmber'");
$_SESSION['challan'][] =$challan_nmber;
$msg='this challan added to bill_bakset';
}
if($responce_code==0)
{
$query1=mysql_query("update table_name set status=3 where bill_number='$challan_nmber' and status=4");
$key=array_search($challan_nmber,$_SESSION['challan']);
unset($_SESSION['challan'][$key]);
$msg='this challan has been removed form bill_bakset';
}
if($query1)
{
//echo $msg;
foreach ($_SESSION['challan'] as $key=>$value)
{
//echo "<h2>".$value."</h2>";
echo '<sup>_'.$value.'</sup>';
}
}
else
{
echo '<i style="color:red">'.mysql_error().'</i>';
}
}

Friday, July 5, 2013

advance css

<style>
p
{
height:50px;
width:100px;
border:1px solid red;
}
p:nth-of-type(1)
{
color: red;
}

p:nth-of-type(2)
{
color:green;
}
p:nth-of-type(1):hover
{
color:blue;
}
p:first-child, p:last-child
{
background-color:plum
}
</style>


<div>
<?php
function abc()
{
for($a=1;$a<10;$a++)
{
echo '<p>'.$a.'</p>';
}
}
abc();
?>
</div>