Friday, July 26, 2013

mouse pointer 2

<STYLE TYPE="text/css">
<!--

BODY{
overflow-x:hidden;
}

.s1
{
  position  : absolute;
  font-size : 10pt;
  color     : blue;
  visibility: hidden;
}

.s2
{
  position  : absolute;
  font-size : 18pt;
  color     : red;
visibility : hidden;
}

.s3
{
  position  : absolute;
  font-size : 14pt;
  color     : gold;
visibility : hidden;
}

.s4
{
  position  : absolute;
  font-size : 12pt;
  color     : lime;
visibility : hidden;
}

//-->
</STYLE>

<body>
<DIV ID="div1" CLASS="s1">*</DIV>
<DIV ID="div2" CLASS="s2">**</DIV>
<DIV ID="div3" CLASS="s3">***</DIV>
<DIV ID="div4" CLASS="s4">****</DIV>

<p align="center"><font face="arial" size="-2">This free script provided by</font><br>
<font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
Kit</a></font></p>

<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">

/*
Script by Mike McGrath- http://website.lineone.net/~mike_mcgrath
Featured on JavaScript Kit (http://javascriptkit.com)
For this and over 400+ free scripts, visit http://javascriptkit.com
*/

//Updated Feb 20th, 08 by JavaScriptKit.com: Script now compatible in IE7/FF

var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes

var nav = (!document.all || window.opera);
var tmr = null;
var spd = 50;
var x = 0;
var x_offset = 5;
var y = 0;
var y_offset = 15;

document.onmousemove = get_mouse;

function get_mouse(e)
{  
  x = (nav) ? e.pageX : event.clientX+standardbody.scrollLeft;
  y = (nav) ? e.pageY : event.clientY+standardbody.scrollTop;
  x += x_offset;
  y += y_offset;
  beam(1);    
}

function beam(n)
{
  if(n<5)
  {
document.getElementById('div'+n).style.top=y+'px'
document.getElementById('div'+n).style.left=x+'px'
document.getElementById('div'+n).style.visibility='visible'
    n++;
    tmr=setTimeout("beam("+n+")",spd);
  }
  else
  {
     clearTimeout(tmr);
     fade(4);
  }  
}

function fade(n)
{
  if(n>0)
  {
document.getElementById('div'+n).style.visibility='hidden'
    n--;
    tmr=setTimeout("fade("+n+")",spd);
  }
  else clearTimeout(tmr);
}

// -->
</SCRIPT>
</body>

Mouse_arrow_trail_magic using javascript

Download code-:
https://docs.google.com/file/d/0BweG5sKiHRrxTGVnREI1Ykotamc/edit?usp=sharing

Tuesday, July 23, 2013

mail function php

download link#1-:
https://skydrive.live.com/embed?cid=FD752051A76BA4FA&resid=FD752051A76BA4FA%21880&authkey=AK3j7yjdx8XkRqA

downlink#2-
https://docs.google.com/file/d/0BweG5sKiHRrxTV90QkRSb1N2Z3M/edit?usp=sharing

Monday, July 22, 2013

javascript ajax

download-: https://docs.google.com/file/d/0BweG5sKiHRrxanJlLVZ3c2wzeFE/edit?usp=sharing

foreign key

ALTER TABLE table_name
 ADD CONSTRAINT key_id
 FOREIGN KEY (colum_name)
 REFERENCES second_table(primary_key_column)

Saturday, July 20, 2013

import excel data into mysql using php script

    <?php
error_reporting(0);
    /********************************************************************************************/
    /* Code at http://legend.ws/blog/tips-tricks/csv-php-mysql-import/
    /* Edit the entries below to reflect the appropriate values
    /********************************************************************************************/
    $databasehost = "localhost";
    $databasename = "testdb";
    $databasetable = "name";
    $databaseusername ="root";
    $databasepassword = "";
    $fieldseparator = ",";
    $lineseparator = "\n";
    $csvfile = "d:/123.csv";
    /********************************************************************************************/
    /* Would you like to add an ampty field at the beginning of these records?
    /* This is useful if you have a table with the first field being an auto_increment integer
    /* and the csv file does not have such as empty field before the records.
    /* Set 1 for yes and 0 for no. ATTENTION: don't set to 1 if you are not sure.
    /* This can dump data in the wrong fields if this extra field does not exist in the table
    /********************************************************************************************/
    $addauto = 0;
    /********************************************************************************************/
    /* Would you like to save the mysql queries in a file? If yes set $save to 1.
    /* Permission on the file should be set to 777. Either upload a sample file through ftp and
    /* change the permissions, or execute at the prompt: touch output.sql && chmod 777 output.sql
    /********************************************************************************************/
    $save = 1;
    $outputfile = "output.sql";
    /********************************************************************************************/
    if(!file_exists($csvfile)) {
    echo "File not found. Make sure you specified the correct path.\n";
    exit;
    }
    $file = fopen($csvfile,"r");
    if(!$file) {
    echo "Error opening data file.\n";
    exit;
    }
    $size = filesize($csvfile);
    if(!$size) {
    echo "File is empty.\n";
    exit;
    }
    $csvcontent = fread($file,$size);
    fclose($file);
    $con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
    @mysql_select_db($databasename) or die(mysql_error());
    $lines = 0;
    $queries = "";
    $linearray = array();
    foreach(split($lineseparator,$csvcontent) as $line) {
    $lines++;
    $line = trim($line," \t");
    $line = str_replace("\r","",$line);
    /************************************************************************************************************
    This line escapes the special character. remove it if entries are already escaped in the csv file
    ************************************************************************************************************/
    $line = str_replace("'","\'",$line);
    /***********************************************************************************************************/
    $linearray = explode($fieldseparator,$line);
    $linemysql = implode("','",$linearray);
    if($addauto)
    $query = "insert into $databasetable values('','$linemysql');";
    else
    $query = "insert into $databasetable values('$linemysql');";
    $queries .= $query . "\n";
    @mysql_query($query);
    }
    @mysql_close($con);
    if($save) {
    if(!is_writable($outputfile)) {
    //echo "File is not writable, check permissions.\n";
    }
    else {
    $file2 = fopen($outputfile,"w");
    if(!$file2) {
    echo "Error writing to the output file.\n";
    }
    else {
    fwrite($file2,$queries);
    fclose($file2);
    }
    }
    }
    echo "Found a total of $lines records in this csv file.\n";
echo 'task complete';
    ?>

Restore backup file in mysql using php

      <?php
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
$table_name = "employee";
$backup_file  = "/tmp/employee.sql";
$sql = "LOAD DATA INFILE '$backup_file' INTO TABLE $table_name";
mysql_select_db('test_db');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not load data : ' . mysql_error());
}
echo "Loaded  data successfully\n";
mysql_close($conn);
?>     

Backup Mysql Database using php script

 <?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
$table_name = "table_name";
$backup_file  = "path:\table_name";
$sql = "SELECT * INTO OUTFILE '$backup_file' FROM $table_name";

mysql_select_db('DB_name');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not take data backup: ' . mysql_error());
}
echo "Backedup  data successfully\n";
mysql_close($conn);
?>

--------------------------- Another Method----------------------------

      <?php
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$backup_file = $dbname . date("Y-m-d-H-i-s") . '.gz';
$command = "mysqldump –opt -h $dbhost -u $dbuser -p $dbpass ".
           "test_db | gzip > $backup_file";

system($command);
?>     

Friday, July 19, 2013

Object Oriented Programming - OOP PHP using static

class and public method

<?php
class dateNow
{
protected $_dateNow='';

public function getCurrentDate()
{
$_dateNow=date("y-m-d");
return $_dateNow;
}

public function future_date()
{
$abc=date("y-m-d",strtotime("+ 7 days"));
return $abc;
}

}

$magicdate=new dateNow();
echo $magicdate->getCurrentDate();
echo '<br />';
echo $magicdate->future_date();
?>

Thursday, July 18, 2013

Create class and method

<?php
class dateNow
{
protected $_dateNow='';

public function getCurrentDate()
{
$_dateNow=date("y-m-d");
return $_dateNow;
}


}
$call_date=new dateNow();
echo $call_date->getCurrentDate();
?>

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>