Saturday, November 23, 2013

convert new line (in textarea) to br tag using javascript and php

[-------------------------------- using javascript ------------------------------ ]

var str = document.getElementById("heading_description").value;
var res = str.replace(/\n/g, '<br />');
document.getElementById("your_id").value=res;

[-------------------------------- using PHP ------------------------------- ]
<?php
function nl2br2($string) {
$string = str_replace(array("\r\n", "\r", "\n"), "<br />", $string);
echo $string;
}

$data="

sdfdsf

sdf
sdfds
fsdf

";

nl2br2($data);
?> 

Sunday, November 10, 2013

create daily folder under every month of folder under every year folder using php

$fodler_array=array(date("Y"), date("m"), date("d"));

foreach($fodler_array as $data)
{
if(!is_dir("assets/".$data))
{
echo '<br />';
mkdir("assets/".$data);
echo 'folder created in assest'.$data;
}
else
{
echo 'folder all ready exits<br />';
}
}

Saturday, November 9, 2013

Find browser name using php

<?php
$browser="";
     if(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]),strtolower("MSIE"))){$browser="ie";}
else if(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]),strtolower("Presto"))){$browser="opera";}
else if(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]),strtolower("CHROME"))){$browser="chrome";}
else if(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]),strtolower("SAFARI"))){$browser="safari";}
else if(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]),strtolower("FIREFOX"))){$browser="firefox";}
else {$browser="other";}
echo $browser;
?>

Wednesday, October 2, 2013

resize any image using php

$im_link='your img path';

$filename=str_replace(" ", "%20",$im_link);
$max_width=630; /* set your div frame width */
$max_height=1000; /* set your div frame height*/

$data = getimagesize($filename);
$_orig_width = $data[0];
$_orig_height = $data[1];

if($_orig_width>$max_width)
{
$new_big_img_width_per=($max_width*100)/$_orig_width;
$new_big_img_height=($_orig_height*$new_big_img_width_per)/100;

$final_height=round($new_big_img_height,0);
$final_width=$max_width;
}
else
{
$final_height=$final_width='auto';
}


echo '<img src="'.$im_link.'" height="'.$final_height.'" width="'.$final_width'" />


.........................................enjoy................................................

Sunday, September 15, 2013

hide any popup or required object when click outside of the object

/* just replace the #selector and enjoy */
var mouse_is_inside = false;

$(document).ready(function()
{
    $('#profile_links').hover(function(){
        mouse_is_inside=true;
    }, function(){
        mouse_is_inside=false;
    });

    $("body").mouseup(function(){
        if(! mouse_is_inside) $('#profile_links').hide();

/* if(! mouse_is_inside)
 {
 $('#login_box').hide();
  $('#master_loader').hide();
 }
 */
    });

$('#login_box').hover(function(){
        mouse_is_inside=true;
    }, function(){
        mouse_is_inside=false;
    });

    $("body").mouseup(function(){
        //if(! mouse_is_inside) $('#login_box').hide();
if(! mouse_is_inside)
 {
 $('#login_box').hide();
  $('#master_loader').hide();
 }

    });
});

Saturday, August 17, 2013

Download PDF books

This folder have containing following pdfs.
1. [SitePoint] Simply JavaScript
2. ASP NET - Web Developers Guide
3. Beginning_MYSQL_5_with_Visual_Studio.NET_2005
4. Java Swing, 2nd Edition
5. jQuery.in.Action.Feb.2008.Manning (2)
6. Operating System Concepts
7. Oracle 9i
8. PHP A BEGINNERS GUIDE
9. SCJP Sun Certified Programmer for Java 6

Download Link #1-: https://drive.google.com/folderview?id=0BweG5sKiHRrxa0gtT2wwYzdBV0k&usp=sharing


Download shopping cart template

Regular Expression Syntax in PHP


Regular Expression Syntax

^ – Start of string
$ – End of string
. – Any single character
( ) – Group of expressions
[] – Item range ( e.g. [afg] means a, f, or g )
[^] – Items not in range ( e.g. [^cde] means not c, d, or e )
- (dash) – character range within an item range ( e.g. [a-z] means a through z )
| (pipe) – Logical or ( e.g. (a|b) means a or b )
? – Zero or one of preceding character/item range
* – Zero or more of preceding character/item range
+ – One or more of preceding character/item range
{integer} – Exactly integer of preceding character/item range ( e.g. a{2} )
{integer,} – Integer or more of preceding character/item range ( e.g. a{2,} )
{integer,integer} – From integer to integer (e.g. a{2,4} means 2 to four of a )
\ – Escape character
[:punct:] – Any punctuation
[:space:] – Any space character
[:blank:] – Any space or tab
[:digit:] – Any digit: 0 through 9
[:alpha:] – All letters: a-z and A-Z
[:alnum:] – All digits and letters: 0-9, a-z, and A-Z
[:xdigit:] – Hexadecimal digit
[:print:] – Any printable character
[:upper:] – All uppercase letters: A-Z
[:lower:] – All lowercase letters: a-z

check two variable containing strings are same or not

<?php
$t=strcmp("dabc","abc");
if($t==0)
echo 'both string are same';
else
echo 'string are not same';
 ?>

Friday, August 16, 2013

select mutipal record from more than one table without join


SELECT
   table1.id,
table1.user_id,
 table2.email,
table2.name FROM table1, table2
 WHERE table1.user_id=table2.user_id

Thursday, August 15, 2013

Downlaod some awesome jquery plugins.
like-:
audio/video.
desktop backgroundImage channger
webcam

-----------------------link---------------
https://drive.google.com/folderview?id=0BweG5sKiHRrxbTZGRVpLUWdqeEU&usp=sharing

Sunday, August 11, 2013

paging in php

<html>
<head>
<title>Paging Using PHP</title>
</head>
<body>
<?php
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$rec_limit = 10;
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
mysql_select_db('test_db');
/* Get total number of records */
$sql = "SELECT count(emp_id) FROM employee ";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
$row = mysql_fetch_array($retval, MYSQL_NUM );
$rec_count = $row[0];
if( isset($_GET{'page'} ) )
{
   $page = $_GET{'page'} + 1;
   $offset = $rec_limit * $page ;
}
else
{
   $page = 0;
   $offset = 0;
}
$left_rec = $rec_count – ($page * $rec_limit);
$sql = "SELECT emp_id, emp_name, emp_salary ".
       "FROM employee ".
       "LIMIT $offset, $rec_limit";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
    echo "EMP ID :{$row['emp_id']}  <br> ".
         "EMP NAME : {$row['emp_name']} <br> ".
         "EMP SALARY : {$row['emp_salary']} <br> ".
         "——————————–<br>";
if( $page > 0 )
{
   $last = $page – 2;
   echo "<a href=\"$_PHP_SELF?page=$last\">Last 10 Records</a> |";
   echo "<a href=\"$_PHP_SELF?page=$page\">Next 10 Records</a>";
}
else if( $page == 0 )
{
   echo "<a href=\"$_PHP_SELF?page=$page\">Next 10 Records</a>";
}
else if( $left_rec < $rec_limit )
{
   $last = $page – 2;
   echo "<a href=\"$_PHP_SELF?page=$last\">Last 10 Records</a>";
}
mysql_close($conn);
?>

Thursday, August 8, 2013

Add days in current date [php]

$current_date=date("Y-m-d");
//$last_date=date("Y-m-d",strtotime(' +7 day'));
$event_day=date("Y-m-d",strtotime(' +8 day'));

echo $event_day;

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>

Wednesday, June 12, 2013

Count days between two days (allies-: age calC)

<?php

$startTimeStamp = strtotime("2012/06/12");
$endTimeStamp = strtotime("2014/07/12");
$timeDiff = abs($endTimeStamp - $startTimeStamp);
$numberDays = $timeDiff/86400;  // 86400 seconds in one day
// and you might want to convert to integer
$numberDays = intval($numberDays);
if($numberDays>=365)
{
$get_year=round(($numberDays/365),0);
$remain_days=$numberDays-(365*$get_year);

if($remain_days>=30)
{
$get_mnth=round(($remain_days/30),0);
$get_remain_days=$remain_days-(30*$get_mnth);
$final_date=$get_year.' years '.$get_mnth.' Month '.$get_remain_days.' Days';
}

}
if($numberDays<365 && $numberDays>=30)
{
$get_mnth=round(($numberDays/30),0);
$find_days=$numberDays-(30*$get_mnth);
$final_date=$get_mnth.' month '.$find_days." days";
}
if($numberDays<30)
{
$final_date=$numberDays .' Days';
}

echo $final_date;

?>

Thursday, May 23, 2013

left join


select a.id,b.phone
from a
right join b
on a.id=b.emp_id

where a and b is table

Monday, May 20, 2013

upload server image in local disk using php



<?php
function img_url()
{

$num=rand(1,99999999999999999999)-rand(5000,8585858571);
$urls=$_SERVER['REMOTE_ADDR'];
$ip=$_SERVER['HTTP_HOST'];

$filename=$num."_".$urls;
$img = 'img/'.$filename.'.jpg';
file_put_contents($img, file_get_contents($url));
$file_location='http://www.'.$ip.'/'.$img;

//echo $file_location;

//echo '<img src="'.$file_location.'" height="auto" width="auto" style="border:0px solid green" />';
echo '
<img src="'.$url.'" />
';
}

img_url();

?>

Thursday, April 4, 2013

my others blogs

data fetching while scrolling just like facebook


<script language="javascript" src="http://www.infoonnet.com/js/jquery.js"></script>
<script>
$(document).scroll(function(){
    if ($(window).scrollTop() + $(window).height() == $(document).height())
{
       document.getElementById("a").innerHTML+='<div style="height:100%; border:1px solid red" id="a">pag1 1</div>';
    }
});
</script>



<div style="height:100%; border:1px solid red" id="a">
pag1 1
</div>
<div style="height:100%; border:1px solid red" id="b">
pag1 1
</div>

Tuesday, April 2, 2013

set row value in numeric order if your data position is unformate

old
inserted Id
2
5
4
3
new
inserted Id
1
2
3
4


alter table table_name drop id;

 ALTER TABLE `table_nmae` ADD `id` INT(255) NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`)

you have to run both code at a same type

Wednesday, March 27, 2013

get and split url using javascript


<script>
function getPathFromUrl() {
  var url = window.location.href;


  if(url.indexOf("html") != -1)
     url = url.split(".")[0];

window.location.href;


  //return url;
}
$("#a").click(function(){
     alert(getPathFromUrl());//this will alert the url without querystring
});
</script>

any type of file restriction from server


RewriteEngine on
rewritecond %{http_host} ^www.domain.in [nc]
rewriterule ^(.*)$ http://domain.in/$1 [r=301,nc]


# Disable directory listing from this point
Options -Indexes

# Prevent viewing of htaccess file
<Files ~ "^\">
order allow,deny
deny from all
satisfy all
</Files>

# Force all PDF files to download
# Requires Apache Header Module - this will work for any file extensions
# below code it will automaticaly  download
<FilesMatch "\.(http://www.karyd.in?i:pdf)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

<FilesMatch \.(?i:gif|jpe?g|png|css|js)$>
    Order Deny,Allow
    Deny from all
</FilesMatch>

<FilesMatch /folder2/folder22/.*>
    Order Deny,Allow
     Deny from all
</FilesMatch>

<FilesMatch (robots\.txt)$>
    Order Deny,Allow
    Allow from all
</FilesMatch>

AuthType Basic
AuthName "Personal use"
AuthUserFile /full/path/to/.htpasswd
Require valid-user

Saturday, March 16, 2013

put intry number on every entry in mysql

you can say.. it will show the position of entry



SELECT
    @row_number := IFNULL(@row_number, 0) + 1 AS row_number,
    id,
    data
FROM abc
WHERE 1 = 1





entry_position id name
1 5255 sudhir
2 54585 mohan
here 1 and 2 will show automatically

Mysql data 10 record per page


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>pencil</title>
<script language="javascript" src="js/jquery.js"></script>
<script>

$(document).ready(function(){
  $("div a").click(function(){
$("div a").css("font-weight","normal");
$("div a").css("text-decoration","none");

    $(this).css("font-weight","bold");
$(this).css("text-decoration","underline");
$(this).attr("target","f1");
  });
});
</script>
<style>
.ss
{
color:blue;
}

.first a, .not_first a
{
text-decoration:none;
color:#c30;
font-family:Arial, Helvetica, sans-serif;
font-weight:normal;
font-size:12px;

}


.first a:hover, .not_first a:hover, .pp
{
text-decoration:underline;
height:20px;
width:20px;
font-weight:bold;
font-size:14px;

}
.first,.not_first:hover
{

text-decoration:underlinel;
font-weight:bold;
cursor:pointer;
height:15px;
width:15px;
float:left;
text-align:center;
padding:2px;
margin:2px;
}
.not_first
{
border:1px solid #C30;
background-color::#FFF
color:#C30;
font-weight:bold;
cursor:pointer;
float:left;
height:15px;
width:15px;
text-align:center;
padding:2px;
margin:2px;
line-height:15px;
}
</style>
</head>

<body>
<?php include("config.php");?>
<?php
mysql_connect($db_server,$db_user,$db_pass);

mysql_query("create database pagerank");
mysql_query("use ".$db);
mysql_query("create table abc (id int (255), data varchar (500)) if not exits ");

for($a=1;$a<=5;$a++)
{
/* remove this comment if u want to insert two*5 query at a time
mysql_query("insert into abc (data) values ('sudhir k gupta') ");
mysql_query("insert into abc (data) values ('rajesh k gupta') ");
*/
}


$a=mysql_num_rows(mysql_query("select * from abc"));
echo '<h3>total Data is '.$a.'<br />';
$limit1=0;
$limit2=$limit1+$data_per_page;
$page=$a/$data_per_page;
//$b=round($page,-0.5);
$b=$page;
$last_value=round($a,-0.5)/$data_per_page;
//echo ' b is'.$b.'<br />';
$result2=mysql_query("select * from abc limit 0,$b");
$result=mysql_query("select * from abc limit $limit1,$limit2");
while($row=mysql_fetch_array($result))
{
echo $row['id'].'-'. $row['data'];
echo '<br />';
}

for($c=0; $c<$b;$c++)
{
$d=$c+1;

if($c==$d)
{
echo '<div class="first all_page"><a href="index.php?num='.$c.'&subs='.$d.'" />'.$d.'</a></div>';
}
else
{
echo '<div class="not_first all_page"><a href="index.php?num='.$c.'&subs='.$d.'" />'.$d.'</a></div>';
}

}

?>

<?php
if(isset($_REQUEST['subs']))
{
$a=$_REQUEST['num'];
//$i=1;
$limit1=1;
$limit2=$a*$data_per_page;
$limit3=$limit2+$data_per_page;
echo 'limit '.$limit2.' to'.$limit3;
echo "<hr />";
$result=mysql_query("select * from abc limit $limit2,$data_per_page");
while($row=mysql_fetch_array($result))
{
echo $row['id'].'-'. $row['data'];
echo '<br />';
}
}
?>
<iframe src="" id="f1"></iframe>
</body>
</html>

add config file 

<?php
$db_server='127.0.0.1';
$db="pagerank";
$db_user="root";
$db_pass="";
$db_table="abc";
$data_per_page=2;

?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>pencil</title>
</head>

<body>

<?php
mysql_connect("127.0.0.1","root","");

mysql_query("create database pagerank");
mysql_query("use pagerank");
mysql_query("create table abc (id int (255), data varchar (500)) if not exits ");
/*
for($a=1;$a<=2;$a++)
{
mysql_query("insert into abc (data) values ('sudhir k gupta') ");
mysql_query("insert into abc (data) values ('rajesh k gupta') ");
}
*/
mysql_query("use pagerank");

$a=mysql_num_rows(mysql_query("select * from abc"));
echo '<h3>total Data is '.$a.'<br />';
$limit1=0;
$limit2=$limit1+5;
$page=$a/5;
$b=round($page,0);
$result2=mysql_query("select * from abc limit 0,$b");
$result=mysql_query("select * from abc limit $limit1,$limit2");
while($row=mysql_fetch_array($result))
{
echo $row['id'].'-'. $row['data'];
echo '<br />';
}
echo '<table><tr>';
for($c=0; $c<=$b;$c++)
{
echo '<form action="" method="get">
<input type="hidden" value="'.$c.'" name="num" />
';
echo '<th><input type="submit" name="subs" value="'.$c.'" /></th></form>';
}
echo '</tr></table>';
?>

<?php
if(isset($_REQUEST['subs']))
{
$a=$_REQUEST['num'];
//$i=1;
$limit1=1;
$limit2=$a*10;
$limit3=$limit2+10;
echo 'limit '.$limit2.' to'.$limit3;
echo "<hr />";
$result=mysql_query("select * from abc limit $limit2,10");
while($row=mysql_fetch_array($result))
{
echo $row['id'].'-'. $row['data'];
echo '<br />';
}

}
?>
</body>
</html>

Friday, March 15, 2013

create DB, table and insert data using php


<?php
mysql_connect("127.0.0.1","root","");
mysql_query("create database pagerank");
mysql_query("use pagerank");
mysql_query("create table abc (id int (255), data varchar (500)) if not exits ");
for($a=1;$a<2;$a++)
{
mysql_query("insert into abc (data) values ('sudhir k gupta') ");
mysql_query("insert into abc (data) values ('rajesh k gupta') ");
}
?>

here i am using for loop. so that  i can insert many data at a time
set a<100. it will insert same data 100 time.

Mysql Delete Command

delete from abc
delete from abc where id between 1 and 10
delete from abc where id=1


abc is table name