Tuesday 27 December 2011

jQuery Util Class

code: save file jUtil.js

function chkCharacter(obj,maxlimit,objMessage) {
    var objMessage,field,num;
    objMessage=document.getElementById(objMessage);
    field=obj;
    num=(maxlimit-field.value.length);
    if(num<=0) {
        num=0;
        objMessage.style.color='red';
    } else {
        objMessage.style.color='green';
    }
    objMessage.innerHTML=num+" Character Remaining.";
    if (field.value.length > maxlimit)
        field.value = field.value.substring(0, maxlimit);
}

function isnotemail(email) {
        var regEx = /^[\w\.\+-]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,6}$/;
        if(!regEx.test(email))
          {
            return true;
          }
          return false;
}
////////////////////////////////////////////////////////////////////
var charSetName="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
function isName(myst) {
    var i;
    for (i = 0; i < myst.length; i++) {
        var c = myst.charAt(i);
        if (charSetName.indexOf(c) < 0) {
            return false;
        }
    }
    return true;
}

var charSetNameOther=" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
function isNameOther(myst) {
    var i;
    for (i = 0; i < myst.length; i++) {
        var c = myst.charAt(i);
        if (charSetNameOther.indexOf(c) < 0) {
            return false;
        }
    }
    return true;
}

var numSet="1234567890";
function isNumber(myst) {
    var i;
    for (i = 0; i < myst.length; i++) {
        var c = myst.charAt(i);
        if (numSet.indexOf(c) < 0) {
            return false;
        }
    }
    return true;
}
var numSetDec="1234567890.";
function isNumberDec(myst) {
    var i,noOfDec=0,decPos=0;
    var splitArr;
    for (i = 0; i < myst.length; i++) {
        var c = myst.charAt(i);
        if(c=='.') {
            noOfDec++;
            decPos=i;
        }
        if (numSetDec.indexOf(c) < 0) {
            return false;
        }
    }
   
    if(noOfDec>=1) {
        splitArr=myst.split(".");
        //alert("splitArr.length="+splitArr.length);
        if(splitArr.length>2) {
            //alert("Invalid Number");   
            return false;
        } else {
            var firstVal=splitArr[0];
            var secondValue=splitArr[1];
            //alert(secondValue.length);
            if(secondValue.length==0 || secondValue.length>2) {
                //alert("Invalid format");
                return false ;
            }
           
        }
    }
   
   
    return true;
}
/////////////////get Date auto fill Date /////////////////////////////
/*function fillDate(curCtrl,nextCtrl) {
        var dateVal,fullDate;
        var toDay,dd,mm,yyyy;
        var splitDate,searchSep;
        dateVal=jQuery.trim($("#"+curCtrl).val());
        toDay=new Date();
        dd=toDay.getDate();
        mm=toDay.getMonth()+1;
        yyyy=toDay.getFullYear();
        if(dateVal=="") {
            fullDate=dd+"-"+mm+"-"+yyyy;
            $("#"+curCtrl).val(fullDate);
        } else {
            searchSep=dateVal.indexOf("-");
            if(searchSep==-1) {
                if(parseInt(dateVal)>31) {
                     alert("Wrong date range");
                     return;
                }
                fullDate=dateVal+"-"+mm+"-"+yyyy;
            } else {
                splitDate=dateVal.split("-");
                fullDate=splitDate[0];
                if(splitDate[1]==undefined || splitDate[1]=="") {
                    fullDate=fullDate+"-"+mm;
                } else {
                    fullDate=fullDate+"-"+splitDate[1];
                }
                if(splitDate[2]==undefined || splitDate[2]=="") {
                    fullDate=fullDate+"-"+yyyy;
                } else {
                    fullDate=fullDate+"-"+splitDate[2];
                }
            }
            $("#"+curCtrl).val(fullDate);
        }
       
        if(jQuery.trim(nextCtrl)!="") {
            $("#"+nextCtrl).focus();
        }
    }*/
    function fillDate(curCtrl,nextCtrl) {
        var dateVal,fullDate;
        var toDay,dd,mm,yyyy;
        var splitDate,searchSep;
        dateVal=jQuery.trim($("#"+curCtrl).val());
        toDay=new Date();
        dd=toDay.getDate();
        mm=toDay.getMonth()+1;
        yyyy=toDay.getFullYear();
        var currentDate=dd+"-"+mm+"-"+yyyy;
        if(dateVal=="") {
            fullDate=dd+"-"+mm+"-"+yyyy;
            $("#"+curCtrl).val(fullDate);
        } else {
            searchSep=dateVal.indexOf("-");
            if(searchSep==-1) {
                if(parseInt(dateVal)>31 || parseInt(dateVal)<1) {
                     //alert("Wrong date range.");
                    $("#"+curCtrl).val(currentDate);
                     return;
                }
                fullDate=dateVal+"-"+mm+"-"+yyyy;
            } else {
                splitDate=dateVal.split("-");
                fullDate=splitDate[0];
                //alert(fullDate);
                if(splitDate[1]==undefined || splitDate[1]=="" || parseInt(splitDate[1])<1) {
                    fullDate=fullDate+"-"+mm;
                } else {
                    fullDate=fullDate+"-"+splitDate[1];
                }
                if(splitDate[2]==undefined || splitDate[2]=="" || parseInt(splitDate[2])<1) {
                    fullDate=fullDate+"-"+yyyy;
                } else {
                    var yRem=parseInt(splitDate[2]);
                    if(yRem>=1 && yRem<=25) {
                        splitDate[2]=parseInt(splitDate[2])+2000;
                    }
                    fullDate=fullDate+"-"+splitDate[2];
                }
            }
            $("#"+curCtrl).val(fullDate);
            if(!chkForLeap(fullDate)) {
                $("#"+curCtrl).val(currentDate);
                $("#"+curCtrl).focus();
            }
           
        }
       
        if(jQuery.trim(nextCtrl)!="") {
            $("#"+nextCtrl).focus();
        }
    }
   
    function chkForLeap(dt) {
        var ans=true;
        var oldDt,dd,mm,yyyy,lp,lpFeb,i;
        var monthArray=new Array(12);
        for (i=0;i<12; i++) {
            monthArray[i]=new Array(2);
        }
        monthArray[0][0]=1;
        monthArray[0][1]=31;
        monthArray[1][0]=2;
        monthArray[1][1]=29;
        monthArray[2][0]=3;
        monthArray[2][1]=31;
        monthArray[3][0]=4;
        monthArray[3][1]=30;
        monthArray[4][0]=5;
        monthArray[4][1]=31;
        monthArray[5][0]=6
        monthArray[5][1]=30;
        monthArray[6][0]=7;
        monthArray[6][1]=31;
        monthArray[7][0]=8;
        monthArray[7][1]=31;
        monthArray[8][0]=9;
        monthArray[8][1]=30;
        monthArray[9][0]=10;
        monthArray[9][1]=31;
        monthArray[10][0]=11;
        monthArray[10][1]=30;
        monthArray[11][0]=12;
        monthArray[11][1]=31;
        oldDt=dt;
        spDate=oldDt.split("-");
        dd=parseInt(spDate[0]);
        mm=parseInt(spDate[1]);
        yyyy=parseInt(spDate[2]);
        var currentYear,toDay;
          toDay=new Date();
          currentYear=toDay.getFullYear();
       
        var reg = /^\d{1,2}\-\d{1,2}\-\d{4}$/;
        if(!oldDt.match(reg)) {
            //alert("Invalid date format: ");
            ans=false;
            return ans;
        }
         
        if(mm>12 || mm<1) {
            //alert("Invalid date format: ");
            $("#"+curCtrl).val(currentDate);
              ans=false;
            return ans;
        }
       
        if(yyyy>currentYear || yyyy<(currentYear-25)){
               //alert("Invalid year");
            $("#"+curCtrl).val(currentDate);
               ans=false;
            return ans;
        }
        lp=yyyy%4;
        lpFeb=lp==0?29:28;
        monthArray[1][1]=lpFeb;
        if(dd>monthArray[mm-1][1] || dd<1) {
            //alert("Invalid day of date, you could not enter "+dd +" as it is greater than "+monthArray[mm-1][1]);
            $("#"+curCtrl).val(currentDate);
            ans=false;
            return ans;
        }
        return ans;
    }
   
///////////////////////////////////////////////////////////////////////////
function checkRoomSearchDate(input) {
    var validformat=/^\d{2}\/\d{2}\/\d{4}$/;
    var returnval=false;
    if (!validformat.test(input))
        returnval=false;
    else {
        var monthfield=input.split("/")[0];
        var dayfield=input.split("/")[1];
        var yearfield=input.split("/")[2];
        var returnval = new Date(yearfield, monthfield-1, dayfield);
        /*if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
        returnval=false; else returnval=t*/
    }
    return returnval;
}
function jShow(obj) {   
    $("#"+obj).show();       
}
function jHide(obj) {
    $("#"+obj).hide();       
}
function objShow(obj) {
    var ct=document.getElementById(obj);
    ct.style.display='';   
}
function objHide(obj) {
    var ct=document.getElementById(obj);
    ct.style.display='none';   
}
function showErr(msg) {
    var matter="<div class='notification error'>";
    matter=matter+"<div class='text'>";
    matter=matter+"    <p><strong></strong>"+msg +"</p></div></div>";
    return matter;                     
}
/*function showErr(msg) {
    var matter="<div class='notification error'>";
    matter=matter+"<div class='text'>";
    matter=matter+"    <p><strong>Error!</strong>"+msg +"</p></div></div>";
    return matter;                     
}*/
function showSucc(msg) {
    var matter="<div class='notification success'>";
    matter=matter+"<div class='text'>";
    matter=matter+"    <p><strong>Success!</strong>"+msg +"</p></div></div>";
    return matter;                     
}
function nextFocus(nextID) {
    $("#"+nextID).focus();                         
}
function setFocusSubmit(e){
 var cd=0;
 if(window.event) {
  cd = e.keyCode;
 } else if(e.which) {
  cd = e.which;
 }
 if(cd==13) {
  return true;
 } else {
  return false;
 }
}
function setFocusDate(e){
 var cd=0;
 if(window.event) {
  cd = e.keyCode;
 } else if(e.which) {
  cd = e.which;
 }
 if(cd==9) {
   
  return true;
 } else {
  return false;
 }
}


function getIndexs(listBoxCtrl) {
    var listBox=document.getElementById(''+listBoxCtrl+'');
    var totalIndexes=listBox.length-1;
    return totalIndexes;
}


function doAjax(urlStr,POSTorGET,variableAndValue) {
        var ans="";
        $.ajax( {
                            type: POSTorGET,
                            async: false,
                           url: urlStr,
                           data: variableAndValue,
                            timeout: 10000,
                            cache:false,
                             success: function(msg){ans=msg;},
                            error: function(xhr) {
                                            if (xhr.responseText)         
                                            ans=xhr.responseText;
                                            else
                                            ans="I don't know! My Processor Has Been HACKED!";
                                                }
                        }
                    );
        return ans;           
    }
   
    // HOW TO USE doAjax???
    /*function doAddAction() {
        var a1,a2,a3,dataVal;
        var a1Val,a2Val,a3Val;
        var urlStr="xmlPost.php";
        var postOrGet="POST";
        var ans;
        var forHideDiv,forShowDiv;
        forHideDiv="";
        forShowDiv="";
        a1Val="This is a1 val";
        a2Val="This is a2 val";
        a3Val="This is a3 val";
        var variableAndValue={a1:a1Val,a2:a2Val,a3:a3Val};
        ans=doAjax(urlStr,postOrGet,variableAndValue);
        alert(ans);
}*/

Wednesday 21 December 2011

How can track Ip address in php

Here with the help of APPs you can track the ip.
These details include Geographic location information (includes country, region/state, city, latitude, longitude and telephone area code.), 

<?php
 $ip=$_SERVER["REMOTE_ADDR"];
$handle = fopen("http://api.ipinfodb.com/v3/ip-city/?key=5b32848aa72361c4efdef63111d6e3d9247e076891f5248eec0a5be1208993e6&ip=".$ip, 'r');
$tt=fgets($handle, 4096);
echo '<br>';
list($statusCode, $statusMessage, $ipAddress,$countryCode,$countryName,$regionName,$cityName,$zipCode,$latitude,$longitude,$timeZone) = split(';', $tt);
echo "Ip-Address->".$ipAddress;
echo '<br>';
echo "Country Name->".$countryName;
echo '<br>';
echo "Country Code->".str_ireplace('-', '', $countryCode);
echo '<br>';
echo "City Name->".str_ireplace('-', '', $cityName);
fclose($handle);

Make php counter

Make php counter
Using PHP and a plain text file this has never been easier. The example below uses a flat-text database so no MySQL database is needed. 
First, lets make a new php page and also a count.txt file with just 0 digit in it. Upload the count.txt file on your web server. Depending on server configuration you may need to change the permission for this file to 777 so it is writeable by the counter script that we are going to use. Now, lets do the actual PHP code.  
<?php
$count = file_get_contents("count.txt");
$count = trim($count);
$count = $count + 1;
$fl = fopen("count.txt","w+");
fwrite($fl,$count);
fclose($fl);
include('count.txt');// Show counter
?>
First line opens the count.txt file and reads the current counter value. Then the trim() function is used to remove any new line characters so we have an integer. On the next line we increment the current counter value by one and then using the fopen, fwrite and fclose commands we write the new value to our count.txt file.

php Util Classes

php Util Classes

Php connection util Classes Code


code: save file UtilClass.php
<?php
class UtilClass {
    public $utilMySqlServerIP;
    public $utilDB ;
    public $utilUser;
    public $utilPass;
    public $utilLink,$utilIsMYSQLLinked,$utilIsDBConnected;
    public static $utilTitle,$utilDescription,$utilKeywords,$utilAuthor;
    public $utilAns;
   
    public function __construct() {
        $this->utilMySqlServerIP = "localhost";
        $this->utilUser = "root";//"root";
        $this->utilPass = "";//"";
        $this->utilDB = "photo-gallery";
        $this->utilAns=false;
    }
    /////////////////// Start SEO Functions ///////////////////////////////////////////////
    public static function getTitle() {
        self::$utilTitle="Photo Gallety";
        return (self::$utilTitle);
    }
    public static function getDescription(){
        self::$utilDescription="Description";
        return (self::$utilDescription);   
    }
    public static function getKeywords(){
        self::$utilKeywords="Keywords";
        return (self::$utilKeywords);   
    }
    public static function getAuthor(){
        self::$utilAuthor="Author";
        return (self::$utilAuthor);   
    }
    public function getCreatedByName() {
        return "CreatedByName";   
    }
    public function getCreatedByWebAddress() {
        return "CreatedByWebAddress";   
    }
    public function getWebName() {
        return "WebName";   
    }
    public function getWebURL() {
        return "WebURL";   
    }
    /////////////////// End SEO Functions ///////////////////////////////////////////////
   
    /////////////////// Start Host Functions ///////////////////////////////////////////////
    public function getHost() {
        return $this->utilMySqlServerIP;   
    }
    public function getDb() {
        return $this->utilDB;   
    }
    public function getUser() {
        return $this->utilUser;   
    }
    public function getPass() {
        return $this->utilPass;   
    }
    ///////////// Start Date and Time Functins////////////////
    public function todayDDMMMYY($dt,$format='d-M-Y') {
        date_default_timezone_set('Asia/Calcutta');
        return date($format,strtotime($dt));
    }
   
    public function todayMMDDYY( $format = 'm-d-Y h:i:s A' ) {
        date_default_timezone_set('Asia/Calcutta');
        return date($format);
    }
    public function todayYYYYMMDD( $format = 'Y-m-d h:i:s A' ) {
        date_default_timezone_set('Asia/Calcutta');
        return date($format);
    }
    public function toDayDate( $format = 'm/d/Y' ) {
        date_default_timezone_set('Asia/Calcutta');
        return date($format);
    }
    public function toDayYear( $format = 'Y' ) {
        return date($format);
    }
////////////////// Start quoteToDbl Function //////////////////
    public function quoteToDbl(&$input) {
        $input=str_replace("'","''",$input);
        $input=trim($input);
    }
    public function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
     }
   
////////////////// End quoteToDbl Function //////////////////
   
////////////////// Start openCon Function //////////////////
    public function openCon() {
        $utilAns=false;
        try {
            $this->utilLink = mysql_connect($this->utilMySqlServerIP, $this->utilUser, $this->utilPass);
            if (!is_resource($this->utilLink) || !$this->utilLink) {
                $utilAns=false;
                $utilIsMYSQLLinked=false;
            }
            else {
                $utilIsMYSQLLinked=true;
                if(mysql_select_db($this->utilDB,$this->utilLink)) {
                    $utilIsDBConnected=true;
                    $utilAns=true;   
                } else {
                    $utilIsDBConnected=false;
                    $utilAns=false;
                }
            }
           
        }
        catch(Exception $ee){
            $utilIsDBConnected=false;
            $utilIsMYSQLLinked=false;
            $utilAns=false;
        }
        return $utilAns;
    }
    ////////////////// End openCon Function //////////////////
   
    ////////////////// Start sendEMail Function //////////////////
    public function sendEMail($tto, $fFrom, $sSubject, $bBody) {
        /*if($tto=="") {
            $tto="to@to.com";
        }
        if($fFrom=="") {
            $fFrom="from@from.com";
        }
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'To: '.$tto . "\r\n";
        $headers .= 'From: '.$fFrom . "\r\n";
        mail($tto, $sSubject, $bBody, $headers);*/
        $html_message = $bBody;
        $mail = new PHPMailer();
        $mail->From = $fFrom;
        $mail->FromName = "Test".' '."Mail"; //name
        $mail->Subject = $sSubject;
        $mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
        $mail->MsgHTML($html_message);
        $mail->AddAddress($tto);
        $mail->Username = 'noreply@firstmedicalservices.com';
        $mail->Password = 'noreply';
        $mailAns = $mail->Send();
        return $mailAns;
    }
    ////////////////// End sendEMail Function //////////////////
   
    ////////////////// Start autoGeneratePass Function //////////////////
    public function autoGeneratePass() {
        $newpass="";
        for($i=1;$i<=2;$i++){
            $newpass=$newpass.chr(rand(65, 90));//A-Z
            $newpass=$newpass.chr(rand(48, 57));//0-9
            //$newpass=$newpass.chr(rand(97, 122));//a-z
        }
        return $newpass;
    }
    ////////////////// End autoGeneratePass Function //////////////////
   
    ////////////////// Start makeMD5 Function //////////////////
    public function makeMD5($st) {
        $md=md5($st);
        return $md;
    }
   
    public function counters($fileName) {
        $count = file_get_contents($fileName);//create txt file and give 0 values in .txt file
        $count = trim($count);
        $count = $count + 1;
        $fl = fopen($fileName,"w+");
        fwrite($fl,$count);
        fclose($fl);
    }

    ////////////////// End makeMD5 Function //////////////////
   
    ////////////////// Start exportToExcelUtil Function //////////////////
    public function exportToExcelUtil($filename,$data) {
        header("Content-type: application/octet-stream");
        header("Content-Disposition: attachment; filename=$filename");
        header("Pragma: no-cache");
        header("Expires: 0");
        echo  $data;
    }
    ////////////////// End exportToExcelUtil Function //////////////////
   
    ////////////////// Start secureSql Function //////////////////
    public function secureSql($val) {
        $val = str_ireplace("script", "blocked", $val);
        $val = mysql_escape_string($val);
        $this->quoteToDbl($val);
        return $val;
    }
    ////////////////// End secureSql Function //////////////////
       
    ////////////////// Start getRandomFileName Function //////////////////   
    public function getRandomFileName() {
        $rndFileName=$this->makeMD5($this->today());
        return $rndFileName;
    }
    ////////////////// End getRandomFileName Function //////////////////   
   

    ////////////////// Start getScript Name/ get Current Page Name Function //////////////////   
    function getScript() {
        $file = $_SERVER["SCRIPT_NAME"];
        $break = explode('/', $file);
        $pfile = $break[count($break) - 1];
        return $pfile;
    }
    ////////////////// End getScript Name/ get Current Page Name Function //////////////////

    ////////////////// Start exeQuery Function //////////////////
    public function exeQuery($qry) {
        echo $qry;
        try    {
            $res = mysql_query($qry, $this->utilLink);
            if(!is_resource($res) || (!$res)) {
                $res=false;
            } else {
                $numRows = mysql_num_rows($res);
                if($numRows<=0) {
                    $res=false;
                }
            }
            return $res;
        }
        catch(Exception $ee){
            return (false);
        }
    }
    ////////////////// End exeQuery Function //////////////////
   
    ////////////////// Start closeCon Function //////////////////
    public function closeCon() {
        mysql_close($this->utilLink);   
    }
    ////////////////// End closeCon Function //////////////////
    #----------------------------Start Utility Function ------------------#
   
    public function __destruct() {
        if($this->utilAns==true) {
        $this->closeCon();}
    }
}
?>
code: save file UtilClass.php
<?php
include_once("UtilClass.php");
class classes1 extends UtilClass {
    var $host;
    var $db ;
    var $user;
    var $pass;
    var $link,$isDBConnect;
    var $isError,$errorValue;
    var $dt;
    var $adminEmail,$adminMobile,$adminEmailPass,$adminEmailPort,$adminEmailHost,$scrollText;
   
    function __construct() {
        parent::__construct();
        $this->host = parent::getHost();
        $this->db = parent::getDb();
        $this->user = parent::getUser();
        $this->pass = parent::getPass();
        try {
            $this->link = mysql_connect($this->host, $this->user, $this->pass);
            if (!is_resource($this->link)) {
                $this->isDBConnect=false;
            }
            else {
                $this->isDBConnect=true;
            }
            mysql_select_db($this->db,$this->link);
            $this->getAdminAllInfo();
        }
        catch(Exception $ee){
            $this->link=false;
        }
    }
   
    public function setCon() {
        $this->host = parent::getHost();
        $this->db = parent::getDb();
        $this->user = parent::getUser();
        $this->pass = parent::getPass();
        try {
            $this->link = mysql_connect($this->host, $this->user, $this->pass);
            if (!is_resource($this->link)) {
                $this->isDBConnect=FALSE;
            }
            else {
                $this->isDBConnect=TRUE;
            }
            mysql_select_db($this->db,$this->link);
        }
        catch(Exception $ee){
            $this->link=FALSE;
        }
    }
    public function getTotalRecord($table) {
        $res=false;
        $sSql="SELECT COUNT(*) AS total FROM $table";
        try {
             $rs=$this->exeQuery($sSql);
             if($rs) {
             $fQury=mysql_fetch_array($rs);
             return $fQury['total'];
             }
             else { return 0; }
             
        } catch(Exception $ee){
            $res=false;       
        }
        return $res;           
    }
   
    public function activeDeactive($ID,$isActive,$tb, $colName) {
        $ans="No";
         $sSql="Update $tb set isActive=$isActive where $colName=$ID";
        try {
             $rs=$this->exeQuery($sSql);
             if($rs) {
                 $ans="Yes";
             }  else { $ans="No"; }
             
        } catch(Exception $ee){
            $ans="No";       
        }
        echo $ans;           
    }
    public function deleteRecord($ID,$tb,$colName) {
        $ans="No";
         $sSql="delete from $tb where $colName=$ID";
        try {
             $rs=$this->exeQuery($sSql);
             if($rs) {
                 $ans="Yes";
                //unlink("../images/$dr/$ID.jpg");
             }  else { $ans="No"; }
             
        } catch(Exception $ee){
            $ans="No";       
        }
        echo $ans;           
    }
       
///////////////////////////////////////////////////////////////////////////////////////////
    public function exeQuery($query) {
        $res=false;
        try    {
            $res = mysql_query($query, $this->link);
        }
        catch(Exception $ee){
            $res=false;
        }
        return $res;
    }

    public function getRow($res) {
        $arr = @mysql_fetch_array($res, MYSQL_BOTH);
        return $arr;
    }
   
    public function close()  {
 }
 public function __destruct() {
  mysql_close($this->link);
    }

}
   
?>

Creating Paging using PHP and MySQL

Creating Paging using PHP and MySQL with classes

Paging means showing your query result in multiple pages instead of just put them all in one long page.

MySQL helps to generate paging by using LIMIT clause which will take two arguments. First argument as OFFSET and second argument how many records should be returned from the database.

Below is a simple example to fetch records using LIMIT clause to generate paging.

crate file example.php
<?php
    include("page.class.php");
    mysql_connect('localhost', 'root', '');
    mysql_select_db('pager');
    $pager = new paging();
    $pager->PageNumber=$_GET[PageNumber];
    $pager->sql_query('SELECT * FROM books'); //first time query
   
   
   
    echo "<br>Total Pages: ".$pager->TotalPage();
    echo "<br>Total Records: ".$pager->TotalRecord();
    echo "<br>Current Page  : ".$pager->PageNumber();
    echo "<br>Next Page  : ".$pager->NextPage();
    echo "<br>Previous Page : ".$pager->PreviousPage();
    echo "<br>Remaining Page : ".$pager->RemainingPage();
   
    echo "<div style=\"background:gray;\" id=\"records\">";
        echo"<hr>";

    foreach($pager->mysql_fetch() as $row){
        echo "<br>".$row['ID']."-".$row['BookName'];
    }

    echo "</div>";
   
    echo "<div style=\"background:gray; display:none;\" id=\"pending\"><img src=\"ajax_small.gif\" ></div>";
     echo"<hr>";

    ////////////PreviousPage//////////////////////
    if($pager->PreviousPage())
    {
    echo " <a href='?PageNumber=".$pager->PreviousPage()."'>Previous</a>";
    }
    ///////////////////////////////////////////////////
   

    foreach($pager->PageLink() as $key=>$value){
        if($pager->PageNumber()==$key)
        {       
            echo "<b>".$key."</b>";   
        }
        else
        {
            echo " <a href='?PageNumber=".$key."' >".$key."</a>";       
        }
   
    }
   
   
        ////////////PreviousPage//////////////////////
    if($pager->NextPage())
    {
        echo " <a href='?PageNumber=".$pager->NextPage()."'>Next</a>";   
    }
  ?>
create paging classes
paging.php
<?Php
class paging
    {
        public $PageNumber=1;
        var $PerPages = 10;
        var $PageNumberLimit=10;
        var $PerPageStart=0;
       
    function sql_query($sql)
    {
        $this->sql_num = mysql_query($sql); //execute query
        $this->PageCalc();
         $this->sql=mysql_query("$sql LIMIT  $this->PerPageStart , $this->PerPages");               
    }
    function TotalPage()
    { 
             $this->TotalPage = $this->TotalRecord() / $this->PerPages;
             return ceil($this->TotalPage);
     }
    function TotalRecord()
    {
            $this->TotalRecord=@mysql_num_rows($this->sql_num);
            return $this->TotalRecord;
    }
    function RemainingPage()
    {
            $this->RemainingPage=$this->TotalPage()-$this->PageNumber;
            return $this->RemainingPage;
    }
    function PageCalc()
    {
        if($this->PageNumber>$this->TotalPage() or empty($this->PageNumber))
        {
            $this->PageNumber=1;
        }
        $this->PerPageStart=(($this->PageNumber-1) * $this->PerPages+1)-1;
    }
    function PageLink()
    {
        $this->calc = ceil(($this->PerPageStart) / $this->PerPages / $this->PageNumberLimit);
            for($b=0;$b <= $this->calc ;$b++){   
                $this->StartCalc =  $b * $this->PageNumberLimit;
                $this->EndCalc = $this->StartCalc + $this->PageNumberLimit ;
                    if ($this->EndCalc <= $this->TotalPage)
                    {
                        if($this->PageNumber >= $this->StartCalc)
                        {
                            $this->End = $this->EndCalc;
                            $this->Start =$this->StartCalc;
                        }
                    }
                    if ($this->EndCalc >= $this->TotalPage)
                    {
                        if($this->PageNumber >= $this->StartCalc)
                        {
                            $this->End= $this->TotalPage; 
                            $this->Start=$this->StartCalc;
                       }
                    }
            if(empty($this->Start))
            {
            $this->Start=1;
            }
    }   
        for($i=ceil($this->Start); $i <= ceil($this->End) ;$i++){
            $list[$i]=$this->i;   
       
        }
            return $list;
    }
   
    function mysql_fetch()
    {
        while($row=mysql_fetch_array($this->sql))
        {
            $rows[] = $row;
        }
            return $rows;   
    }
     
   
    function PreviousPage()
    {
        if($this->PageNumber)
        {
            $PreviousNumber = $this->PageNumber-1;
        }
            return  $PreviousNumber;
    }
 
    function NextPage()
    {
        if ($this->PageNumber < $this->TotalPage)
        {
            $NextNumber = $this->PageNumber+1;
        }
            return  $NextNumber;
    }
     
    function PageNumber()
    {
            return $this->PageNumber;    
    }
    }
 
?>

how to fix div in bottom/top

how to fix div in bottom/top

<div style="background:#000; height:10px; margin:0 auto ; width:100%; position: fixed; z-index:200; bottom:0px; ">this is testing </div>

How to export mysql data to excel file



I've been able to export any data from MySQL to a csv file.

Export mysql data to excel in php 

Code here :

<?php
$topRow="<table border='1'>";
$bottomRow="</table>";
$columns="<tr><th>Name</th><th>Age</th><th>Phone/Mobile Number</th>";
$columns.="</tr>";
$data="";
$i==1;
///////////////////////////
/// you can also connect database. you fetch data and pass paramete on td tag fields.
/////////////////////
while($i<10){
$nName="<tr><td>".str_replace('"', '""',"Jafar Khan")."</td>";
$age="<td>".str_replace('"', '""',"24")."</td>";
$phoneMobileNumber="<td>".str_replace('"', '""',"9451293997")."</td>";
$line=$nName.$age.$phoneMobileNumber;
 $data.=$line;
$i++ ;}
$data = str_replace("\r", "", ($topRow.$columns.$data.$bottomRow));
function exportToExcelUtil($filename,$data) {
        header("Content-type: application/octet-stream");
        header("Content-Disposition: attachment; filename=$filename");
        header("Pragma: no-cache");
        header("Expires: 0");
        echo  $data;
    }
exportToExcelUtil("test.xls",$data);
?>

How to create dive corner without image

How to create dive corner without image

How to create  dive corner without image 
Here you make comer without image with the help of jQuery.  
Code Here :
 <!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>Untitled Document</title>
<script language="JavaScript" src="jquery-1.6.js"></script>
<script language="JavaScript" src="jquery.corner.js"></script>
<script language="javascript">
$('#divID').corner("10px");
</script>
</head>

<body>

<div id="divID" style="width:300px; height:200px; background-color:#090;" >
&nbsp;test round couner
</div>
</body>
</html>
Example