Saturday, December 15, 2012

Prepared Statement in php Mysql


<?php

 $dbh = new PDO('mysql:host=localhost;dbname=test','root','');
$stmt = $dbh->prepare("INSERT INTO Writers (name) VALUES (:name)");
$stmt->bindParam(':name', $name);
$name = 'jeeva';
$stmt->execute();
$name = 'jeevanandham';
$stmt->execute();
?>

Saturday, August 4, 2012

How to dynamically disable the .numeric() in jquery.alphanumeric.js


Put Following in the jquery.alphanumeric.js. Then use $(element).removeNumeric(); to disable the numeric method
$.fn.removeNumeric = function() { return this.data("numeric.decimal", null).data("numeric.negative", null).data("numeric.callback", null).unbind("keypress", $.fn.numeric.keypress).*unbind("keyup", $.fn.numeric.keyup)*.unbind("blur", $.fn.numeric.blur); }

Thursday, February 16, 2012

zip directory and sub-directory files using php

$s='template';

$zip = new ZipArchive();
if($zip->open('template/template.zip',false ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
}

$this->recursive('template',$zip);

function recursive($s,$zip)
{
$dir = opendir($s);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($s . '/' . $file) ) {
recursive($s . '/' . $file,$zip);
}
else {
$d = end(explode('/',$s));

$zip->addFile($s . '/' . $file,$d.'/'.$file);
}
}
}
closedir($dir);
}

Wednesday, February 15, 2012

Iframe image upload using jquery

<script type='text/javascript'>

$(document).ready(function(){

$('#banner').submit(function(){

$('#imgbanner').attr('src','loading.gif');

});

$('iframe[name=upload_banner]').load(function(){

var result = $(this).contents().text();



if(result !=''){



$('#imgbanner').attr('src',$(this).contents().text());

}

});

});

function gob()

{

$('#bannerdiv').hide();

document.frmb.submit();



}

$(document).ready(function(){

$("#bbtn").click(function(){

$("#banner").click();

});

});

</script>

<style>

div#bannerdiv iframe {

position:fixed;

left:-9000px;

width:1px;

height:1px;

}

div#bannerdiv img {

max-width:150px;

max-height:150px;

}

</style>

<div class="banner">

<div id='bannerdiv' style="padding-left:200px; width:100px;">

<form id='bannerfrm' name="frmb" method='post' enctype='multipart/form-data' action='bannerupload.php' target='upload_banner'>





<p><input type='file' id='banner' name='banner' onchange="gob()" style="display:none;"/> </p>

</form>

<div id="bbtn" name="bbtn" style="background-color:#999999; border:2px double #666666; width:310px; height:100px;">Upload Banner</div>



</div>

<span style="padding-left:220px; padding-bottom:40px;"><img id="imgbanner" /></span>

<iframe name='upload_banner' style="display:none;">

</iframe>

</div>

In bannerupload.php

<?php


Tuesday, January 31, 2012

Horizontally moving gallery image using jquery

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
#slideshow {
border: 1px solid #D8D8D8;
height: 166px;
margin: 0 auto;
position: relative;
width: 220px;
}
element.style {
overflow: hidden;
}
#slideshow #slidesContainer {

height: 163px;

margin: 0 auto;
position: relative;
width: 210px;
}
#slideshow #slidesContainer .slide {
height: 166px;
margin: 0 auto;
width: 210px;
}

#rightControl {
background: url("../images/ph-rigtimg.png") no-repeat scroll 0 0 transparent;
right: -45px;
top: 41px;
width: 21px;
position:absolute;
}
.ph-txtprt {
height: 50px;
margin: 5px 0 10px;
overflow: hidden;
width: 220px;

}
#leftControl {
background: url("../images/ph-leftimg.png") no-repeat scroll 0 0 transparent;
left: -71px;
top: 41px;
width: 21px;
position:absolute;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var cp = 0;
var totalwidth = 210;
var gallery = $('.slide');
var title = $('.ph-txtprt');
var count = gallery.length;
$('#slidesContainer').css('overflow', 'hidden');
gallery.wrapAll('<div id="slideInner"></div>')
gallery.css({
'float' : 'left',
'width' : totalwidth
});
title.css({
'float' : 'left',
'width' : totalwidth
});
$('#slideInner').css('width', totalwidth * count);
$('#titleInner').css('width', totalwidth * count);
$('#slideshow')
.prepend('<span class="control" id="leftControl">Clicking moves left</span>')
.append('<span class="control" id="rightControl">Clicking moves right</span>');

Controls(cp);
$('.control')
.bind('click', function(){
// Determine new position
cp = ($(this).attr('id')=='rightControl') ? cp+1 : cp-1;
Controls(cp);
$('#slideInner').animate({
'marginLeft' : totalwidth*(-cp)
});
$('#titleInner').animate({
'marginLeft' : totalwidth*(-cp)
});
});

function Controls(position){
if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() }

if(position==count-1){ $('#rightControl').hide() } else{ $('#rightControl').show() }
}
});
</script>
</head>
<body>
<div id="slideshow">
<div id="slidesContainer">
<div class="slide">
<img src="1.jpg" width="210" height="156" alt="" />
</div>
<div class="slide">
<img src="2.jpg" width="210" height="156" alt="" />
</div>
<div class="slide">
<img src="3.jpg" width="210" height="156" alt="" />
</div>
</div>
<div style="width:220px;overflow:hidden;float:left; " >
<div id="titleInner" style="height:40px;">
<div class="ph-txtprt" style="width:210; text-align:center;">
<h4>Image1</h4>
</div>
<div class="ph-txtprt" style="width:210; text-align:center;">
<h4>Image2</h4>
</div>
<div class="ph-txtprt" style="width:210; text-align:center;">
<h4>Image3</h4>
</div>
</div></div>
</div>
</body>
</html>

Copy & paste save .. Put three images name as 1,2,3 run it .. Click here for



Monday, January 30, 2012

Check validate webaddress using javascript reg expression


web = 'your web address';
var aweb = ignoreSpaces(web);
var filterweb = /^([A-Za-z0-9_\-\.])+([A-Za-z0-9_\-\.]{2,4})+\.([A-Za-z]{2,4})$/;
if(filterweb.test(aweb)){
        alert('correct')
    }
    else{
       alert('incorrect')
    }
try this for javascript

Bind Some Event to Element and trigger that function when click the element

Scenario: Suppose if we used same click event function in various web pages. if you want do some logic some page button for that need to re...