Pagination with jquery, Ajax, PHP

db.php
<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "pagdb";
$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");
?>

pagination.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>Pagination with Jquery, Ajax, PHP</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
        <script type="text/javascript">
            $(document).ready(function(){
                function loading_show(){
                    $('#loading').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;
                    }
                    
                });
            });
        </script>

        <style type="text/css">
            body{
                width: 800px;
                margin: 0 auto;
                padding: 0;
            }
            
            #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;
			}

        </style>

    </head>
    <body>
	<div style="margin-top:10px;"></div> 
</div> 
<div align="center" style="font-size:24px;color:#cc0000;font-weight:bold">Pagination with jquery, Ajax and PHP</div>
        <div id="container">
            <div class="data"></div>
            <div class="pagination"></div>
        </div>
		http://demos.9lessons.info/counter.html 
    </body>
</html>

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

$query_pag_data = "SELECT msg_id,message from messages LIMIT $start, $per_page";
$result_pag_data = mysql_query($query_pag_data) or die('MySql Error' . mysql_error());
$msg = "";
while ($row = mysql_fetch_array($result_pag_data)) {
$htmlmsg=htmlentities($row['message']);
    $msg .= "<li><b>" . $row['msg_id'] . "</b> " . $htmlmsg . "</li>";
}
$msg = "<div class='data'><ul>" . $msg . "</ul></div>"; // Content for Data


/* --------------------------------------------- */
$query_pag_num = "SELECT COUNT(*) AS count FROM messages";
$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);

/* ---------------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;
}
/* ----------------------------------------------------------------------------------------------------------- */
$msg .= "<div class='pagination'><ul>";

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

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

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

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

// TO ENABLE THE END BUTTON
if ($last_btn && $cur_page < $no_of_paginations) {
    $msg .= "<li p='$no_of_paginations' class='active'>Last</li>";
} else if ($last_btn) {
    $msg .= "<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>";
$msg = $msg . "</ul>" . $goto . $total_string . "</div>";  // Content for pagination
echo $msg;
}

pagdb.sql
-- phpMyAdmin SQL Dump
-- version 3.3.9
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jun 07, 2011 at 08:05 AM
-- Server version: 5.5.8
-- PHP Version: 5.3.5

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `pagdb`
--

-- --------------------------------------------------------

--
-- Table structure for table `messages`
--

CREATE TABLE IF NOT EXISTS `messages` (
  `msg_id` int(11) NOT NULL AUTO_INCREMENT,
  `message` varchar(255) NOT NULL,
  PRIMARY KEY (`msg_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=23 ;

--
-- Dumping data for table `messages`
--

INSERT INTO `messages` (`msg_id`, `message`) VALUES
(1, 'mrshedul arefin'),
(2, 'sabbir'),
(3, 'ahmed'),
(4, 'ripon'),
(5, 'munir'),
(6, 'abul kalam'),
(7, 'topu'),
(8, 'souruv'),
(9, 'younus'),
(10, 'anis'),
(11, 'jahidul'),
(12, 'bulu'),
(13, 'alauddin'),
(14, 'muhit'),
(15, 'modidul'),
(16, 'rakib'),
(17, 'arjullah'),
(18, 'liton'),
(19, 'rajib'),
(20, 'mistri'),
(21, 'shoha'),
(22, 'karim');
Categories: Ajax, JQuery, PHP

JQuery Drop Down Menu Setup-1

April 6, 2011 Leave a comment

bmi.js

var bmi_htmlEdit=0;var bmi_ie;var bmi_ns;var bmi_safari;var bmi_imageObjSelected;var bmi_ffx_op_toolTip=”Shift+R improves the quality of this image. Shift+A improves the quality of all images on this page.”;var bmi_toolTip=”Shift+R improves the quality of this image. Read more…

Categories: JQuery

Confirmation Message Showing in Same Page after Form Fill-up

April 2, 2011 Leave a comment

form.php:

<form name=”frm” action=”contact.php?act=sm” method=”post”>

<table border=”0″ cellspacing=”0″ cellpadding=”5″>
<tr>
<td>Name:</td>
<td><input id=”name1″ name=”name1″ type=”text” size=”32″ /></td>
</tr>
<tr>
<td>Email Address:</td>
<td><input id=”email1″ name=”email1″ type=”text” size=”32″ /></td>
</tr>
<tr>
<td>Subject:</td>
<td><input id=”sub1″ name=”sub1″ type=”text” size=”32″ /></td>
</tr>
<tr>
<td valign=”top”>Message:</td>
<td><textarea id=”msg1″ name=”msg1″ cols=”26″ rows=”5″></textarea></td>
</tr>
<tr>
<td></td>
<td><input id=”submit” name=”submit” type=”submit” value=”Submit” /></td>
</tr>
</table>
</form>

 

contact.php:

<?php
if(isset($_GET[‘act’]))
{
$do=$_GET[‘act’];
switch($do)
{
case ‘form’: show_form();break;
case ‘sm’ : submitted();break;
default : show_form(); break;
}
}

else
{
show_form();
}

function show_form()
{
include_once “form1.php”;
}

function submitted()
{
$name1=$_POST[‘name1′];
$email1=$_POST[’email1′];
$sub1=$_POST[‘sub1’];
$msg1=$_POST[‘msg1’];

if(($name1==””)||($email1==””)||($sub1==””)||($msg1==””))
{
echo “<div><font color=\”RED\”>Sorry! No Field Can Remain Blank.</font></div>     <br />”;
include_once “form1.php”;
}

else
{
//Include your coding here to insert into the database.
echo “<div><font color=\”GREEN\”>Thanks for submitting your message.</font></div>    <br />”;
include_once “form1.php”;
}

}

?>

Categories: PHP

How to Add One HTML to Another HTML

March 31, 2011 Leave a comment

aaa.html:

<script src=”bbb.html”>
</script>

bbb.html:

document.write(‘<div><div>&copy; Copyright <a href=”#”>Company Name</a>. All Rights Reserved.</div></div>’)

 

Categories: HTML

University Template-1

March 18, 2011 Leave a comment

Categories: Website Screenshots

All the States of United States

March 14, 2011 Leave a comment

US States:

AL=Alabama

AK=Alaska

AZ=Arizona

AR=Arkansas

CA=California

CO=Colorado

CT=Connecticut

DE=Delaware

FL=Florida

GA=Georgia

HI=Hawaii

ID=Idaho

IL=Illinois

IN=Indiana

IA=Iowa

KS=Kansas

KY=Kentucky

LA=Louisiana

ME=Maine

MD=Maryland

MA=Massachusetts

MI=Michigan

MN=Minnesota

MS=Mississippi

MO=Missouri

MT=Montana

NE=Nebraska

NV=Nevada

NH=New Hampshire

NJ=New Jersey

NM=New Mexico

NY=New York

NC=North Carolina

ND=North Dakota

OH=Ohio

OK=Oklahoma

OR=Oregon

PA=Pennsylvania

RI=Rhode Island

SC=South Carolina

SD=South Dakota

TN=Tennessee

TX=Texas

UT=Utah

VT=Vermont

VA=Virginia

WA=Washington

WV=West Virginia

WI=Wisconsin

WY=Wyoming

Categories: Uncategorized

Add a Character in Replace of ” ” Into a String

March 9, 2011 Leave a comment

<?php
$str=”If you think that Cloud Computing”;
echo $str.”<br />”;
$wordChunks=explode(” “,$str);
for($i=0;$i<count($wordChunks);$i++)
{
if($i==0)
{
$tmp=$wordChunks[$i];
$new_str=$new_str.$tmp;
}
else
{
$tmp=$wordChunks[$i];
$new_str=$new_str.”-“.$tmp;
}
}
echo $new_str;
?>

OUTPUT:

If you think that Cloud Computing
If-you-think-that-Cloud-Computing

Categories: PHP
Follow

Get every new post delivered to your Inbox.