Wednesday, November 30, 2011

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>

Friday, November 25, 2011

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;    
    }
    }
 
?>



Wednesday, November 23, 2011

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);
    }

}
   
?>

Monday, November 21, 2011

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.

Thursday, November 10, 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);