Pages

PHP OOP PDO Database class example

Read / fetch data with PHP PDO Database Connection Class in Simple way

<?php
class db {
    private $username = "root";
    private $password = "";
    function connect() {
        $username = $this->username;
        $password = $this->password;
        try {
            $conn = new PDO('mysql:host=localhost;dbname=test', $username, $password);
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
        return $conn;
    }
}

class getdata extends db {
    function read() {
        $con = $this->connect();
        $sql = "SELECT * FROM CITY";
        try {
            $citylist = $con->query($sql);
        } catch (Exception $ex) {
        }
        return $citylist;
    }
}

$getdataCity = new getdata();
$citylist = $getdataCity->read();

$a = $citylist->fetchAll();

print_r($a);

if($citylist->rowCount()){
    foreach ($a as $city){
        echo $city['city_name'];
    }
}

Enable and Disable JQuery UI accordion rows

Enable and Disable and selecting JQuery UI accordion rows

$('#sdx').click(function(){

$("#accordion").accordion({
active: 0,
});

$('.ui-accordion-header').addClass('ui-state-disabled').on('click', function () {
return false;
});       

$('.ui-accordion-header').eq(0).removeClass('ui-state-disabled').on('click', function () {
return true;
});

});

Filter numbers only from string PHP

Filter numbers only from string PHP $_get method


$itmidx = $_GET['item'];

$itmid = preg_replace('/[^0-9.]+/', '', $itmidx);

Reset CSS Link Outlines

CSS code to remove outline effect in web page links

a {
   outline: 0;
}
a:hover, a:active, a:focus {
  outline: 0;
}

JQuery if else on hover

CSS styles change on hover state with JQuery if else statement

    $(document).ready(function() {

        $('body').mouseover(function() {

            if ($('.comsec1').is(':hover')) {
                            $('.comsec2').css('width','40%');
           $('.comsec1').css('width','60%');
            }
            
            else if ($('.comsec2').is(':hover')) {
                          $('.comsec2').css('width','60%');
           $('.comsec1').css('width','40%');
            }
            
            else  {
            $('.comsec2').css('width','50%');
            $('.comsec1').css('width','50%');
            }

        });
        
    });

Search This Blog