This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Friday, 29 November 2013

Reading Excel Files In PHP

In this tutorial I’m going to show you how you can use the php library called PHP Excel Reader to read excel files using php. Yes, things like excel readers for php has already been written by smart people in the past so I’m not going to show you how to build an excel reader from scratch. It’s not quite my level yet, I still consider myself a beginner. Anyway, let’s get to the main topic.


Index.php

<?php
include 'excel_reader.php';       // include the class
$excel = new PhpExcelReader;      // creates object instance of the class
$excel->read('data2.xls');   // reads and stores the excel file data

// Test to see the excel data stored in $sheets property
/*echo '<pre>';
var_export($excel->sheets);
echo '</pre>';
*/$rows=$excel->sheets[0]['numRows'];
$cols=$excel->sheets[0]['numCols'];
echo "<table>";
for($i=2;$i<$rows;$i++)
{
echo "<tr>";
for($j=1;$j<$rows;$j++)
{
echo "<td>".$excel->sheets[0]['cells'][$i][$j]."</td>";
//echo $excel->sheets[0]['cells'][$i][$j];
}
echo "</tr>";
}
echo "</table>";
?>

Thursday, 28 November 2013

PHP jQuery Comment/News Updates Script

Hi, today i am going to show you about facebook auto updates, as we seen in facebook at right side top of the corner we able to see the user activity updates, i have done same concept using jquery, ajax and php, let's see how we do this - See more at: http://www.lessoncup.com/2013/11/jquery-news-updates.html#sthash.voMAxzug.dpuf

DEMO                         DOWNLOAD

index.php

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>jQuery News Updates</title>

<script type="text/javascript" src="jquery-1.10.2.min.js"></script>

<script>

$(document).ready(function(){

$('.send').click(function(){

var name=$('#name').val();
var mess=$('#mess').val();
if(name==""){
alert('enter your name');
}else if(mess==""){
alert('enter your message');
}else{

var messdata= "name="+name+"&mess="+mess;
$("#loader").show();
$("#loader").fadeIn(400).html('<img src="loader.gif" align="absmiddle">&nbsp;<span class="loading">Loading updates</span>');
$('.send').css({ "width": "82px", "cursor": "wait" });
$('.send').text('Tweeting wait..');
$.ajax({
type:"post",
data:messdata,
url:"sendmessage.php",
cache:false,
success:function(msg){

$(".forms1").val('');
$("#loader").hide();
$("ul#amsalert").prepend(msg);
$("ul#amsalert li:first").slideDown(500);
$('.send').css({ "width": "40px", "cursor": "pointer" });
$('.send').text('Tweet');

}
});
}
});
});

</script>

<style>

body{ font-family:Verdana, Geneva, sans-serif; color:#000; font-size:11px; background-color:#FFF; margin:0; padding:0;}

.lessoncup{width:300px; height:auto;border:solid #6895CC 1px;-webkit-box-shadow: 0 2px 5px #666;
box-shadow: 0 2px 5px #666; padding:10px;font-family:Arial, Helvetica, sans-serif; font-size:11px; margin:50px 0 0 400px; float:left;}

.messages{width:250px; height:638px; overflow:hidden;border:solid #8CACDD;font-family:Arial, Helvetica, sans-serif;font-size:11px; float:right; border-width:0 0 1px 1px;}

#loader{font-size:12px;display:none; margin:0 auto; width:112px; height:20px; padding:10px;}

#amsalert{ color:#fff; padding:0;list-style:none; margin:0; padding-left:1px;}

#amsalert li{ background-color:#6895CC; margin-top:1px; padding:10px; display:none; cursor:pointer;}

#amsalert li:hover{ background-color:#4E65C0; cursor:pointer;}

#msalert{ color:#fff; padding:0;list-style:none; margin:0; padding-left:1px;}

#msalert li{ background-color:#6895CC; margin-top:1px; padding:10px;}

#msalert li:hover{ background-color:#4E65C0; cursor:pointer;}

#mname{ color:#FF0; font-weight:bold;}

.ul{ margin:0; padding:0; list-style:none;}

.ul li{ padding:10px; padding-bottom:0; font-size:12px; color:#000;}

.send{ background-color:#6895CC; border:none; border-radius:5px; padding:10px; width:40px; cursor:pointer; color:#fff;}

.send:hover{ background-color:#4E65C0;}

.forms1{color:#333;padding:10px; width:200px; border:solid #6895CC 1px; font-size:14px; resize:none; margin:5px 0 5px 0; outline:none;border-radius:5px;}

#formbox{width:240px; height:auto;margin:0 auto;}



</style>

</head>

<body>

<div class="lessoncup">
<div id="formbox">

    <ul class="ul">
      <li> <span> Name:</span><br/>
        <input name="name" type="text" id="name" class="forms1" placeholder="name">
      </li>
      <li>Message<span>:</span><br/>
        <textarea name="mess" class="forms1" id="mess" placeholder="enter message"></textarea>
      </li>
      
      <li style="margin-top:5px;">
        <div class="send">Tweet</div>
      </li>
    </ul>
  </div>
</div>

<div class="messages">
<div id="loader"></div>
<ul id="amsalert">

</ul>
<?php include("messagealerts.php")?>
</div>



<div style="margin:0 auto; clear:both;width:400px;font-family:Verdana, Geneva, sans-serif; font-size:9px; color:#CCC; margin-top:10px;">(c) Mohammad Khasim Productions - for more lessons<strong>&nbsp;<a href="http://www.lessoncup.com" style="text-transform:lowercase;" target="_blank">www.lessoncup.com</a></strong></div>
</body>
</html>

sendmessage.php


<?php
extract($_REQUEST);
include("db.php");

$sql=mysql_query("insert into messages(name,message) values('$name','$mess')");

$msql=mysql_query("select * from messages order by mid desc");
$mrow=mysql_fetch_array($msql);
?>

<li><span id="mname"><?php echo $mrow['name']?></span><br/>
<?php echo substr($mrow['message'],0,40);?>
</li>


messagealerts.php


<?php
extract($_REQUEST);
include("db.php");

$sql=mysql_query("select * from messages order by mid desc limit 0 , 20");
while($row=mysql_fetch_array($sql)){
?>
<ul id="msalert">
<li><span id="mname"><?php echo $row['name']?></span><br/>
<?php echo substr($row['message'],0,40);?>
</li>
</ul>
<?php }?>

Tuesday, 19 November 2013

Create Marker on Google Map Using PHP

In this example , coordinates values are automatically fetch when the user puts marker on the map. This tutorial which I will be teaching here will have Google map, putting,hiding and deleting markers on the map functionality.It is very light weight Google Maps code and easy to use and it is mostly build in javascript.

<!DOCTYPE html>
<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>
<script>
var myCenter=new google.maps.LatLng(51.508742,-0.120850);
var markers = [];
var map;
function initialize()
{
var mapProp = {
center:myCenter,
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
google.maps.event.addListener(map, 'click', function(event) {
placeMarker(event.latLng);
});
function placeMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map,
});
markers.push(marker);
var infowindow = new google.maps.InfoWindow({
content: 'Latitude: ' + location.lat() + '<br>Longitude: ' + location.lng()
});
infowindow.open(map,marker);
}
}
function setAllMap(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
function clearMarkers() {
setAllMap(null);
}
function showMarkers() {
setAllMap(map);
}
// Deletes all markers in the array by removing references to them.
function deleteMarkers() {
clearMarkers();
markers = [];
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<input onclick="clearMarkers();" type=button value="Hide Markers">
<input onclick="showMarkers();" type=button value="Show All Markers">
<input onclick="deleteMarkers();" type=button value="Delete Markers">
<div id="googleMap" style="width:700px;height:400px;"></div>
</body>
</html>

PHP/AJAX Grid View System

Few days ago I have developed a Grid system using PHP, jQuery and Ajax. I want to share this with my dear users. It is not very well parametrized or generic but if have little much understanding of jQuery and Ajax then its easy to use. Give your feed back about zGrid.

Demo                    Download

Friday, 15 November 2013

Php Ajax Datagrid Example

DataGrid has an extremely simple and flexible API. This allows developers to begin using DataGrid very quickly, and allows them to access even advanced features with ease. DataGrid ships with examples covering virtually all features of the grid, that provide a simple and effective way of showing how to use the API. We've taken a few of these examples to convey some idea of the simplicity of using DataGrid in any PHP application.

DataGrid with AJAX features

View Data
Dependent dropdown lists (regions and countries)
Tabular(inline) layout for filtering
AJAX paging, details
Tree PostBack methods: GET, POST and AJAX
etc.

Demo                                              Download

Database:

-- phpMyAdmin SQL Dump
-- version 2.11.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Nov 15, 2013 at 06:37 AM
-- Server version: 5.0.51
-- PHP Version: 5.2.5

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `sales`
--



--
-- Table structure for table `calling_info`
--

CREATE TABLE `calling_info` (
  `call_id` bigint(255) NOT NULL auto_increment,
  `Mobile` varchar(255) NOT NULL,
  `com_name` varchar(255) NOT NULL,
  `telesales` varchar(255) NOT NULL,
  `call_date` varchar(255) NOT NULL,
  `call_date1` datetime NOT NULL,
  PRIMARY KEY  (`call_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1005 ;

Saturday, 9 November 2013

Making/Embed jw Player With PHP

The JW Player is the Internet's most advanced and flexible media player.The JW Player Plugin enables you to embed Flash and HTML5 audio and video, plus RTMP and YouTube streams, on your site using.

The JW Player Plugin makes it extremely easy to deliver Flash and HTML5 video through your website. This plugin has been developed by LongTail Video, the creator of the JW Player, and allows for easy customization and embedding of Flash and HTML5 video using the JW Player in your WordPress posts. It provides support for all of the JW Player 6 configuration options, including custom watermarks, HLS/RTMP streaming and VAST/VPAID advertising.

Key Features
  • Full support for JW Player 6 for Flash and HTML5.
  • Full integration into the WordPress media library. Embed video with the JW Player as you write your posts.
  • Support for adding External Media to your Media Library, including Youtube and RTMP streams.
  • A full featured playlist manager - order your media by simply dragging the mouse.
  • A powerful shortcode system for customizations at embed time.

Friday, 8 November 2013

Free PHP Mass/Bulk Mailer Script

Inbox PHP Mailer & Inbox Mass Mailer is a compact easy to use ,server (web) based email mailer. It is specifically designed for the small business market, not to be the biggest or most featured but to be a clean efficient contact tool helping you to send newsletters to your clients, contact your staff, send one email or many.

Why Emailer
A huge amount of people use web based email services such as Hotmail and Yahoo. If they want to get in touch with you by email, instead of being able to simply click an email link (like users with email clients such as Outlook), they have to go to the email providers website - log in to their account - create a new email - copy your email address across and then finally send the email.

That is a bit of a long way round when you could have a simple form for them to fill in and send to you, so you should have an email form on your website to make it more user friendly for your visitors/potential custmers.c

Steps:
1:  Upload excel file


2:


Thursday, 7 November 2013

Shopping Cart Script Code In PHP

This tutorial is the knowledge of PHP sessions and some array functions. So i am not going to tell you what a shopping cart is? What are sessions and how they work, i will rather jump to how we are going to build a shopping cart. But before this, you can view an online demo of this tutorial and you should also download tutorial files to your computer.

Demo                                   Download

index.php

<?
header("location:products.php");
?>

products.php

<?
include("includes/db.php");
include("includes/functions.php");

if($_REQUEST['command']=='add' && $_REQUEST['productid']>0){
$pid=$_REQUEST['productid'];
addtocart($pid,1);
header("location:shoppingcart.php");
exit();
}
?>
<!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>Products</title>
<script language="javascript">
function addtocart(pid){
document.form1.productid.value=pid;
document.form1.command.value='add';
document.form1.submit();
}
</script>
</head>


<body>
<form name="form1">
<input type="hidden" name="productid" />
    <input type="hidden" name="command" />
</form>
<div align="center">
<h1 align="center">Products</h1>
<table border="0" cellpadding="2px" width="600px">
<?
$result=mysql_query("select * from products");
while($row=mysql_fetch_array($result)){
?>
    <tr>
        <td><img src="<?=$row['picture']?>" /></td>
            <td>   <b><?=$row['name']?></b><br />
            <?=$row['description']?><br />
                    Price:<big style="color:green">
                    $<?=$row['price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['serial']?>)" />
</td>
</tr>
        <tr><td colspan="2"><hr size="1" /></td>
        <? } ?>
    </table>
</div>
</body>
</html>


shoppingcart.php

<?
include("includes/db.php");
include("includes/functions.php");

if($_REQUEST['command']=='delete' && $_REQUEST['pid']>0){
remove_product($_REQUEST['pid']);
}
else if($_REQUEST['command']=='clear'){
unset($_SESSION['cart']);
}
else if($_REQUEST['command']=='update'){
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=intval($_REQUEST['product'.$pid]);
if($q>0 && $q<=999){
$_SESSION['cart'][$i]['qty']=$q;
}
else{
$msg='Some proudcts not updated!, quantity must be a number between 1 and 999';
}
}
}

?>
<!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>Shopping Cart</title>
<script language="javascript">
function del(pid){
if(confirm('Do you really mean to delete this item')){
document.form1.pid.value=pid;
document.form1.command.value='delete';
document.form1.submit();
}
}
function clear_cart(){
if(confirm('This will empty your shopping cart, continue?')){
document.form1.command.value='clear';
document.form1.submit();
}
}
function update_cart(){
document.form1.command.value='update';
document.form1.submit();
}


</script>
</head>

<body>
<form name="form1" method="post">
<input type="hidden" name="pid" />
<input type="hidden" name="command" />
<div style="margin:0px auto; width:600px;" >
    <div style="padding-bottom:10px">
    <h1 align="center">Your Shopping Cart</h1>
    <input type="button" value="Continue Shopping" onclick="window.location='products.php'" />
    </div>
    <div style="color:#F00"><?=$msg?></div>
    <table border="0" cellpadding="5px" cellspacing="1px" style="font-family:Verdana, Geneva, sans-serif; font-size:11px; background-color:#E1E1E1" width="100%">
    <?
if(is_array($_SESSION['cart'])){
            echo '<tr bgcolor="#FFFFFF" style="font-weight:bold"><td>Serial</td><td>Name</td><td>Price</td><td>Qty</td><td>Amount</td><td>Options</td></tr>';
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$pname=get_product_name($pid);
if($q==0) continue;
?>
            <tr bgcolor="#FFFFFF"><td><?=$i+1?></td><td><?=$pname?></td>
                    <td>$ <?=get_price($pid)?></td>
                    <td><input type="text" name="product<?=$pid?>" value="<?=$q?>" maxlength="3" size="2" /></td>                  
                    <td>$ <?=get_price($pid)*$q?></td>
                    <td><a href="javascript:del(<?=$pid?>)">Remove</a></td></tr>
            <?
}
?>
<tr><td><b>Order Total: $<?=get_order_total()?></b></td><td colspan="5" align="right"><input type="button" value="Clear Cart" onclick="clear_cart()"><input type="button" value="Update Cart" onclick="update_cart()"><input type="button" value="Place Order" onclick="window.location='billing.php'"></td></tr>
<?
            }
else{
echo "<tr bgColor='#FFFFFF'><td>There are no items in your shopping cart!</td>";
}
?>
        </table>
    </div>
</form>
</body>
</html>

billing.php

<?
include("includes/db.php");
include("includes/functions.php");

if($_REQUEST['command']=='update'){
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$address=$_REQUEST['address'];
$phone=$_REQUEST['phone'];

$result=mysql_query("insert into customers values('','$name','$email','$address','$phone')");
$customerid=mysql_insert_id();
$date=date('Y-m-d');
$result=mysql_query("insert into orders values('','$date','$customerid')");
$orderid=mysql_insert_id();

$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$price=get_price($pid);
mysql_query("insert into order_detail values ($orderid,$pid,$q,$price)");
}
die('Thank You! your order has been placed!');
}
?>
<!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>Billing Info</title>
<script language="javascript">
function validate(){
var f=document.form1;
if(f.name.value==''){
alert('Your name is required');
f.name.focus();
return false;
}
f.command.value='update';
f.submit();
}
</script>
</head>


<body>
<form name="form1" onsubmit="return validate()">
    <input type="hidden" name="command" />
<div align="center">
        <h1 align="center">Billing Info</h1>
        <table border="0" cellpadding="2px">
        <tr><td>Order Total:</td><td><?=get_order_total()?></td></tr>
            <tr><td>Your Name:</td><td><input type="text" name="name" /></td></tr>
            <tr><td>Address:</td><td><input type="text" name="address" /></td></tr>
            <tr><td>Email:</td><td><input type="text" name="email" /></td></tr>
            <tr><td>Phone:</td><td><input type="text" name="phone" /></td></tr>
            <tr><td>&nbsp;</td><td><input type="submit" value="Place Order" /></td></tr>
        </table>
</div>
</form>
</body>
</html>


functions.php

<?
function get_product_name($pid){
$result=mysql_query("select name from products where serial=$pid");
$row=mysql_fetch_array($result);
return $row['name'];
}
function get_price($pid){
$result=mysql_query("select price from products where serial=$pid");
$row=mysql_fetch_array($result);
return $row['price'];
}
function remove_product($pid){
$pid=intval($pid);
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
if($pid==$_SESSION['cart'][$i]['productid']){
unset($_SESSION['cart'][$i]);
break;
}
}
$_SESSION['cart']=array_values($_SESSION['cart']);
}
function get_order_total(){
$max=count($_SESSION['cart']);
$sum=0;
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$price=get_price($pid);
$sum+=$price*$q;
}
return $sum;
}
function addtocart($pid,$q){
if($pid<1 or $q<1) return;

if(is_array($_SESSION['cart'])){
if(product_exists($pid)) return;
$max=count($_SESSION['cart']);
$_SESSION['cart'][$max]['productid']=$pid;
$_SESSION['cart'][$max]['qty']=$q;
}
else{
$_SESSION['cart']=array();
$_SESSION['cart'][0]['productid']=$pid;
$_SESSION['cart'][0]['qty']=$q;
}
}
function product_exists($pid){
$pid=intval($pid);
$max=count($_SESSION['cart']);
$flag=0;
for($i=0;$i<$max;$i++){
if($pid==$_SESSION['cart'][$i]['productid']){
$flag=1;
break;
}
}
return $flag;
}

?>

db.php

<?
@mysql_connect("localhost","root","") or die("Demo is not available, please try again later");
@mysql_select_db("shopping") or die("Demo is not available, please try again later");
session_start();
?>

Wednesday, 6 November 2013

JQuery ajax method to get content of another file

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="jquery-1.9.0.min.js"></script>
<script>
function fun1()
{
 $.ajax({
  url:"audio.html",
  success: function(data){
   $("#msg").html(data);
   }
  });
}
</script>
</head>

<body>
<input type="button" value="load" onclick="fun1()" />
<div id="msg">
</div>
</body>
</html>

Appending Content In The Div

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style>
#msg{
 width:260px;
 height:60px;
 background-color:#CCC;
 padding:20px;
}
h3{
 width:300px;
 border:1px solid #CCC;
 text-align:center;
 cursor: pointer;
 cursor: hand;
 margin-bottom:20px;
}
</style>
<script src="jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function() {
    $("h3").click(function(){
  $("#msg").append("<p>'Write less: Do more'</p>");  
 });
});
</script>
</head>

<body>
<h3>Click to append Content</h3>
<div id="msg">jQuery is a fast, small and feature-rich <b>JavaScript</b> library.</div>
</body>
</html>

Create Image Slider Using Jquery

In this web design tutorial, we will learn to create custom image slider above using Photoshop, which you can preview the final result from here. Not only will we illustrate it in Photoshop, we will also turn it into a functional design by converting it into HTML/CSS and adding jQuery for its awesome sliding effect.

Demo

<script src="jquery-1.9.1.js"></script>
<script src="jquery.cycle.all.js"></script>
<script>
function slider()
{
$("#div1").cycle({fx:'scrollLeft'})
}
</script>
<body onload="slider()">
<div id="div1" style="position:absolute;top:100;left:100;">
<img src="1.jpg" width="200">
<img src="2.jpg" width="200">
<img src="3.jpg" width="200">
<img src="4.jpg" width="200">
</div>
</body>

Live Table Edit, Delete ,Pagination using Jquery Ajax Php

This post is the example of  live table data edit, delete records with pagination using Jquery, Ajax and PHP. I had implemented this using Jquery .live() function. This script helps you to instantly modify or update the table data.You know that majority of readers had requested this tutorial, hope you guys like it!.


Download Code                                   Live Demo

The tutorial contains  PHP and Javascript files.
index.php
table_data.php
load_data.php
live_edit_table.php
delete_ajax.php
db.php

EditDeletePage.js

Code Start Here:
index.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This is a pagination script using Jquery, Ajax and PHP
     The enhancements done in this script pagination with first,last, previous, next buttons -->

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Live Edit, Pagination and Delete Records with Jquery</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
   <script type="text/javascript" src="EditDeletePage.js"></script>
        <style type="text/css">
            body{
                width: 800px;
                margin: 0 auto;
                padding: 0;
    font-family:Arial, Helvetica, sans-serif
            }
            #loading{
                width: 100%;
                position: absolute;
                top: 100px;
                left: 100px;
    margin-top:200px;
            }
            #container .pagination ul li.inactive,
            #container .pagination ul li.inactive:hover{
                background-color:#ededed;
                color:#bababa;
                border:1px solid #bababa;
                cursor: default;
            }
            #container .data ul li{
                list-style: none;
                font-family: verdana;
                margin: 5px 0 5px 0;
                color: #000;
                font-size: 13px;
            }

            #container .pagination{
                width: 800px;
                height: 25px;
            }
            #container .pagination ul li{
                list-style: none;
                float: left;
                border: 1px solid #006699;
                padding: 2px 6px 2px 6px;
                margin: 0 3px 0 3px;
                font-family: arial;
                font-size: 14px;
                color: #006699;
                font-weight: bold;
                background-color: #f2f2f2;
            }
            #container .pagination ul li:hover{
                color: #fff;
                background-color: #006699;
                cursor: pointer;
            }
   .go_button
   {
   background-color:#f2f2f2;border:1px solid #006699;color:#cc0000;padding:2px 6px 2px 6px;cursor:pointer;position:absolute;margin-top:-1px;
   }
   .total
   {
   float:right;font-family:arial;color:#999;
   }
   .editbox
   {
   display:none;
 
   }
   td, th
   {
   width:20%;
   text-align:left;;
   padding:5px;
   }
   .editbox
   {
   padding:4px;
 
   }
        </style>
    </head>
 <body>
<div id="loading"></div>
<div id="container"></div>
<div style="margin-top:30px">
</div>
    </body>
</html>

EditDeletePage.js

// 9lessons programming blog
// Srinivas Tamada http://9lessons.info
$(document).ready(function()
{
$(".delete").live('click',function()
{
var id = $(this).attr('id');
var b=$(this).parent().parent();
var dataString = 'id='+ id;
if(confirm("Sure you want to delete this update? There is NO undo!"))
{
 $.ajax({
type: "POST",
url: "delete_ajax.php",
data: dataString,
cache: false,
success: function(e)
{
b.hide();
e.stopImmediatePropagation();
}
     });
 return false;
}
});
 

$(".edit_tr").live('click',function()
{
var ID=$(this).attr('id');

$("#one_"+ID).hide();
$("#two_"+ID).hide();
$("#three_"+ID).hide();
$("#four_"+ID).hide();


$("#one_input_"+ID).show();
$("#two_input_"+ID).show();
$("#three_input_"+ID).show();
$("#four_input_"+ID).show();


}).live('change',function(e)
{
var ID=$(this).attr('id');

var one_val=$("#one_input_"+ID).val();
var two_val=$("#two_input_"+ID).val();
var three_val=$("#three_input_"+ID).val();
var four_val=$("#four_input_"+ID).val();

var dataString = 'id='+ ID +'&name='+one_val+'&category='+two_val+'&price='+three_val+'&discount='+four_val;
if(one_val.length>0&& two_val.length>0 && three_val.length>0 && four_val.length>0)
{

$.ajax({
type: "POST",
url: "live_edit_ajax.php",
data: dataString,
cache: false,
success: function(e)
{

$("#one_"+ID).html(one_val);
$("#two_"+ID).html(two_val);
$("#three_"+ID).html(three_val);
$("#four_"+ID).html(four_val);

e.stopImmediatePropagation();

}
});
}
else
{
alert('Enter something.');
}

});

// Edit input box click action
$(".editbox").live("mouseup",function(e)
{
e.stopImmediatePropagation();
});

// Outside click action
$(document).mouseup(function()
{

$(".editbox").hide();
$(".text").show();
});
 
 
//Pagination
function loading_show(){
$('#loading').html("<img src='images/loading.gif'/>").fadeIn('fast');
}
function loading_hide(){
$('#loading').fadeOut('fast');
}              
function loadData(page){
loading_show();                  
$.ajax
({
type: "POST",
url: "load_data.php",
data: "page="+page,
success: function(msg)
{
$("#container").ajaxComplete(function(event, request, settings)
{
loading_hide();
$("#container").html(msg);
});
}
});
}
loadData(1);  // For first time page load default results
$('#container .pagination li.active').live('click',function(){
var page = $(this).attr('p');
loadData(page);
});        
$('#go_btn').live('click',function(){
var page = parseInt($('.goto').val());
var no_of_pages = parseInt($('.total').attr('a'));
if(page != 0 && page <= no_of_pages){
loadData(page);
}else{
alert('Enter a PAGE between 1 and '+no_of_pages);
$('.goto').val("").focus();
return false;
}
});
});

live_edit_ajax

<?php
include("db.php");
if($_POST['id'])
{
$id=mysql_escape_String($_POST['id']);

$name=mysql_escape_String($_POST['name']);
$category=mysql_escape_String($_POST['category']);
$price=mysql_escape_String($_POST['price']);
$discount=mysql_escape_String($_POST['discount']);
$sql = "update products set name='$name',category='$category',price='$price',discount='$discount' where pid='$id'";
mysql_query($sql);

}

?>

load_data.php

<?php

include "db.php";
if($_POST['page'])
{
$page = $_POST['page'];
$cur_page = $page;
$page -= 1;
$per_page = 5; // Per page
$previous_btn = true;
$next_btn = true;
$first_btn = true;
$last_btn = true;
$start = $page * $per_page;


include('table_data.php');

/* ---------------Calculating the starting and endign values for the loop----------------------------------- */
if ($cur_page >= 7) {
    $start_loop = $cur_page - 3;
    if ($no_of_paginations > $cur_page + 3)
        $end_loop = $cur_page + 3;
    else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6) {
        $start_loop = $no_of_paginations - 6;
        $end_loop = $no_of_paginations;
    } else {
        $end_loop = $no_of_paginations;
    }
} else {
    $start_loop = 1;
    if ($no_of_paginations > 7)
        $end_loop = 7;
    else
        $end_loop = $no_of_paginations;
}
/* ----------------------------------------------------------------------------------------------------------- */
$finaldata .= "<div class='pagination'><ul>";

// FOR ENABLING THE FIRST BUTTON
if ($first_btn && $cur_page > 1) {
    $finaldata .= "<li p='1' class='active'>First</li>";
} else if ($first_btn) {
    $finaldata .= "<li p='1' class='inactive'>First</li>";
}

// FOR ENABLING THE PREVIOUS BUTTON
if ($previous_btn && $cur_page > 1) {
    $pre = $cur_page - 1;
    $finaldata .= "<li p='$pre' class='active'>Previous</li>";
} else if ($previous_btn) {
    $finaldata .= "<li class='inactive'>Previous</li>";
}
for ($i = $start_loop; $i <= $end_loop; $i++) {

    if ($cur_page == $i)
        $finaldata .= "<li p='$i' style='color:#fff;background-color:#006699;' class='active'>{$i}</li>";
    else
        $finaldata .= "<li p='$i' class='active'>{$i}</li>";
}

// TO ENABLE THE NEXT BUTTON
if ($next_btn && $cur_page < $no_of_paginations) {
    $nex = $cur_page + 1;
    $finaldata .= "<li p='$nex' class='active'>Next</li>";
} else if ($next_btn) {
    $finaldata .= "<li class='inactive'>Next</li>";
}

// TO ENABLE THE END BUTTON
if ($last_btn && $cur_page < $no_of_paginations) {
    $finaldata .= "<li p='$no_of_paginations' class='active'>Last</li>";
} else if ($last_btn) {
    $finaldata .= "<li p='$no_of_paginations' class='inactive'>Last</li>";
}
$goto = "<input type='text' class='goto' size='1' style='margin-top:-1px;margin-left:60px;'/><input type='button' id='go_btn' class='go_button' value='Go'/>";
$total_string = "<span class='total' a='$no_of_paginations'>Page <b>" . $cur_page . "</b> of <b>$no_of_paginations</b></span>";
$finaldata = $finaldata . "</ul>" . $goto . $total_string . "</div>";  // Content for pagination
echo $finaldata;
}



table_data.php

<?php
$query_pag_data = "SELECT pid,name,category,price,discount from products LIMIT $start, $per_page";
$result_pag_data = mysql_query($query_pag_data) or die('MySql Error' . mysql_error());
$finaldata = "";
$tablehead="<tr><th>Product Name</th><th>Category</th><th>Price</th><th>Discount</th><th>Edit</th></tr>";
while($row = mysql_fetch_array($result_pag_data))
{

$id=$row['pid'];
$name=htmlentities($row['name']);
$category=htmlentities($row['category']);
$price=htmlentities($row['price']);
$discount=htmlentities($row['discount']);

$tabledata.="<tr id='$id' class='edit_tr'>

<td class='edit_td' >
<span id='one_$id' class='text'>$name</span>
<input type='text' value='$name' class='editbox' id='one_input_$id' />
</td>

<td class='edit_td' >
<span id='two_$id' class='text'>$category</span>
<input type='text' value='$category' class='editbox' id='two_input_$id'/>
</td>

<td class='edit_td' >
<span id='three_$id' class='text'>$price $</span>
<input type='text' value='$price' class='editbox' id='three_input_$id'/>
</td>

<td class='edit_td' >
<span id='four_$id' class='text'>$discount $</span>
<input type='text' value='$discount' class='editbox' id='four_input_$id'/>
</td>

<td><a href='#' class='delete' id='$id'> X </a></td>

</tr>";
}
$finaldata = "<table width='100%'>". $tablehead . $tabledata . "</table>"; // Content for Data


/* Total Count */
$query_pag_num = "SELECT COUNT(*) AS count FROM products";
$result_pag_num = mysql_query($query_pag_num);
$row = mysql_fetch_array($result_pag_num);
$count = $row['count'];
$no_of_paginations = ceil($count / $per_page);

?>

delete_ajax.php

<?php
include("db.php");
if($_POST['id'])
{
$id=mysql_escape_String($_POST['id']);
$sql = "delete from products where pid='$id'";
mysql_query($sql);

}
?>

db.php

<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "db";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Opps some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong");

?>