Tuesday, January 29, 2013

Animate div with browser scroll


precurscrol = 0;
$(window).scroll(function () {
    //You've scrolled this much:

totalscroll = $(document).height() - $(window).height();
        curscrol = $(window).scrollTop();
if(curscrol<(totalscroll-115))
{
if(precurscrol>curscrol){ curscrol = curscrol+100;  }
if(curscrol>70 )
{
$("#leftbar").css({'margin-top':curscrol+'px'});
curscrol = curscrol-20;
//$("#leftbar").animate({'margin-top':curscrol+'px'},'fast',function () {})
}
precurscrol = curscrol;
//console.log(precurscrol);

}

});

Monday, January 28, 2013

php ajax pagination

<script type="text/javascript">
function getUser(pno)
{
data = "pno="+pno;

$.ajax({
url: base_url+'/AjaxUser.php',
sync: true,
type: 'POST',
data: data,
success: function(resp) {

$("#listhistory").html(resp);
}
});
}
</script>
<div id="listhistory">
<?php
//Ajax Pagination
$w = '';
// getting page number
$pageno = (isset($_POST['pno']))?$_POST['pno']:'';
// for the filter option
$status = isset($_SESSION['status'])?$_SESSION['status']:'';
$status = (isset($_POST['Status']))?$_POST['Status']:$status;

if(!empty($status))
{
$_SESSION['paystatus'] = $status;
$w .= " and Status='$status'";
}
// page number calculation
if(empty($pageno)) $pageno = 1;
$perpage = 5;
$start = ($pageno-1)*$perpage;
// getting total no rows
$query = "select * from users where 1 $w";
$rett = mysql_query($query,$con);
$totrows = $mysql_num_rows($rett);
$query = "select * from users where 1 $w limit $start, $perpage";
$ret = $mydb->query($query);
$rs = $mydb->result_array($ret);
$i=$start+1;
if($mydb->num_rows($ret)>0)
{
?>
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="tabgray" >
<tr><th>Sno</th><th>Username</th><th>email</th><th>Status</th></tr>
<? foreach($rs as $r) { ?>
<tr><td><?php echo $i; ?></td><td><?php echo $r['username']; ?></td><td><?php echo $r['email'] ?></td><td><?php echo $r['status']; ?></td></tr>
<?
$i++; }}
?>
</table>
<?php
// Pagination Links
$nopages = floor($totrows/$perpage)+(($totrows%$perpage)?1:0);
$lfrom = ($pageno>3)?$pageno-3:1;
$lto = ($pageno+5<$nopages)?$pageno+5:$nopages;
?>
<div>
<div class="pagination" style="float:left;">
<?php if($lfrom!=1) { ?><span class="btn" onclick="getUser(1);">1</span><strong>...</strong><?php } ?>
<?php for($li=$lfrom;$li<$lto;$li++){
$cls = ($pageno==$li)?'btnsel':'btn';
?>
<span class="<?php echo $cls; ?>" onclick="getUser(<?php echo $li; ?>);"><?php echo $li; ?></span>
<?php } ?>
<?php if($nopages>3){ ?><strong>...</strong><span class="btn" onclick="getUser(<?php echo $nopages; ?>);"><?php echo $nopages; ?></span> <?php } ?>
</div>

</div>
</div>
<script type="text/javascript">
getUser(1);
</script>

Sunday, January 27, 2013

how get no of between two dates


       $from = strtotime($from);
  $to = strtotime($to);
$r = $to-$from;
floor($r/86400);

how get no of sundays between to dates


$from = "from date";
$to = "to date";
$sunday = 0;
  $from = strtotime($from);
  $to = strtotime($to);
for($i=$from;$i<=$to;$i+=86400)
  {
  $d = date('w',$i);
if($d=='0') $sunday += 1;
  }

Thursday, January 24, 2013

Jquery Basics things


Jquery Basics:

1)Getting Values of following elements:

a) All form elements
b) Div, span etc

2)Setting values to the following elements:

a) All form elements
b) Div, span etc

3) Check whether the following elements have values or not:

a) All form elements
b) Div, span etc

3) Check whether the following elements displyed or not:

a) All form elements
b) Div, span etc

4) Jquery methods
 a) ajax
 b) post
          c) serialize

5) get and set attribute of elements in jquery.
6) Add or Remove class to elements in jquery.
7) How to apply css to elements in jquery.

Show Hide the corresponding div

<span class="question" id="1">what is your name?</span>
<div id="ans1">
test</div>
<span class="question" id="2">what is your name?</span>
<div id="ans2">
test</div>
<span class="question" id="3">what is your name?</span>
<div id="ans3">
test</div>
$(document).ready(function()

{
 $(".question").click(function()
 {
  id= $(this)attr('id');
  $("#ans"+id).slideToggle();
 }

 )
 }

);

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...