Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Monday, 6 January 2014

Arranging DIVs Horizontally

1 comment
Working with DIV tag is always problem and hard work thats why many web developers avoid creating their websites in DIV tag, in this tutorial, I will show you how to arrange DIVs in horizontal order with CSS.

The HTML Code


This is the html code for 4 divs div.container, div.left, div.middle and div.right.
Note: Below the div.right there is another div with height:0; and width:100% and clear:both, the job of this div is to make sure the floating divs not going outside the container, try on your own to remove the div.clear to see what will happen on those floating div.


   <div class="container">
   <div class="left">Left</div>
   <div class="middle">Middle</div>
   <div class="right">Right</div>
   <div class="clear"></div>
   </div>



The CSS Code


.container{
width:600px;
padding:0;
border:5px solid #ddd;
margin:0 auto;
}

.left{
float:left;
width:150px;
height:300px;
text-align:center;
background:#4b471a;
font:18px Arial, Helvetica, sans-serif;
font-weight:bold;
color:#1b1b1b;
}

.middle{
float:left;
width:300px;
height:300px;
text-align:center;
background:#a19c5a;
font:18px Arial, Helvetica, sans-serif;
font-weight:bold;
color:#1b1b1b;
}

.right{
float:left;
width:150px;
height:300px;
text-align:center;
background:#4b471a;
font:18px Arial, Helvetica, sans-serif;
font-weight:bold;
color:#1b1b1b;
}

.clear{
clear:both;
height:0;
width:100%;
}

Output



By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Sunday, 5 January 2014

Google Map API Zoom The Marker Example

Leave a Comment
Google Map API Marker is a powerful API to use for web page to mark on the map for example the location of your business office. This tutorial can use in all framework as long as the framework use html language to render the content to client side.

You can refer here for more information of Google Map API

Let see the example in asp.net framework.

The Javascript to call map and marker

var map;
function initializeGMap() {
           var Centre = new google.maps.LatLng(3.15681, 101.714696);
            var mapOptions = { zoom: 12, center: Centre, mapTypeId: google.maps.MapTypeId.ROADMAP };
            map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

            var KLCC = new google.maps.LatLng(3.15681, 101.714696);
            var marker = new google.maps.Marker({ position: KLCC, map: map, title: 'Kuala Lumpur City Center' });  
        }
        google.maps.event.addDomListener(window, 'load', initializeGMap);


The Zoom Marker Script

function getInfo() {
            var contentString = '<div style="width: 400px; min-height: 100px;">';
            contentString += '<table style="font-size:12px; width:400px; height: 100px; border: none !important;">';
            contentString += '<tr style=\"background:none !important;\">';
            contentString += '<td valign=\"top\" style=\"width: 80px; height: 80px;border-bottom:none;\"></td>';
            contentString += '<td valign=\"top\" style=\"border-bottom:none;\">';
            contentString += '<table><tr style=\"background:none !important;\">';
            contentString += '<td style=\"font-size:16px;border-bottom:none;\">';
            contentString += '<b>Kuala Lumpur City Centre</b></td></tr>';
            contentString += '<tr style=\"background:none !important;\">';
            contentString += '<td style=\"border-bottom:none;\">';
            contentString += 'Kuala Lumpur City Centre<br />50450 Kuala Lumpur<br/>Wilayah Persekutuan Kuala Lumpur, Malaysia</td>';
            contentString += '</tr></table></td></tr><tr style=\"background:none !important;\">';
            contentString += '<td style=\"border-bottom:none;\">&nbsp;</td></tr>';
            contentString += '<tr style=\"background:none !important;border-bottom:none;\">';
            contentString += '<td colspan="2"></td></tr><tr style="background:none !important;">';
            contentString += '<td colspan="2" style=\"border-bottom:none;\"><b>Phone:</b>-</td>';
            contentString += '</tr></td></tr></table></div>';
            var infoWindowMarker = new google.maps.InfoWindow({
                content: contentString
            });
            var myLatLng = new google.maps.LatLng(3.15681, 101.714696);
            var myMarker = new google.maps.Marker({
                position: myLatLng,
                map: map,
                title: 'Kuala Lumpur City Centre'
            });
            infoWindowMarker.close();
            infoWindowMarker.open(map, myMarker);
            map.setCenter(myLatLng);
            map.setZoom(17);

        }


The ASPX Page

<div style="width: 600px; height: 400px; float:left;">
        <div id="map-canvas" style="width: 100%; height: 100%;">
        </div>
    </div>
    <div style="float:right;">
        <div id="Div1" style="width: 100%; height: 100%; text-align:left; padding:20px;">
            <asp:Button ID="Button1" runat="server" Text="Zoom The Marker" OnClientClick="getInfo();return false;" />
        </div>
    </div>


Full Code

Note : This example use default MasterPage from Visual Studio 2010

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script>

        var map;

        function initializeGMap() {

            var Centre = new google.maps.LatLng(3.15681, 101.714696);
            var mapOptions = { zoom: 12, center: Centre, mapTypeId: google.maps.MapTypeId.ROADMAP };
            map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

            var KLCC = new google.maps.LatLng(3.15681, 101.714696);
            var marker = new google.maps.Marker({ position: KLCC, map: map, title: 'Kuala Lumpur City Center' });
            
        }
        google.maps.event.addDomListener(window, 'load', initializeGMap);
    
        function getInfo() {
            var contentString = '<div style="width: 400px; min-height: 100px;">';
            contentString += '<table style="font-size:12px; width:400px; height: 100px; border: none !important;">';
            contentString += '<tr style=\"background:none !important;\">';
            contentString += '<td valign=\"top\" style=\"width: 80px; height: 80px;border-bottom:none;\"></td>';
            contentString += '<td valign=\"top\" style=\"border-bottom:none;\">';
            contentString += '<table><tr style=\"background:none !important;\">';
            contentString += '<td style=\"font-size:16px;border-bottom:none;\">';
            contentString += '<b>Kuala Lumpur City Centre</b></td></tr>';
            contentString += '<tr style=\"background:none !important;\">';
            contentString += '<td style=\"border-bottom:none;\">';
            contentString += 'Kuala Lumpur City Centre<br />50450 Kuala Lumpur<br/>Wilayah Persekutuan Kuala Lumpur, Malaysia</td>';
            contentString += '</tr></table></td></tr><tr style=\"background:none !important;\">';
            contentString += '<td style=\"border-bottom:none;\">&nbsp;</td></tr>';
            contentString += '<tr style=\"background:none !important;border-bottom:none;\">';
            contentString += '<td colspan="2"></td></tr><tr style="background:none !important;">';
            contentString += '<td colspan="2" style=\"border-bottom:none;\"><b>Phone:</b>-</td>';
            contentString += '</tr></td></tr></table></div>';
            var infoWindowMarker = new google.maps.InfoWindow({
                content: contentString
            });
            var myLatLng = new google.maps.LatLng(3.15681, 101.714696);
            var myMarker = new google.maps.Marker({
                position: myLatLng,
                map: map,
                title: 'Kuala Lumpur City Centre'
            });
            infoWindowMarker.close();
            infoWindowMarker.open(map, myMarker);
            map.setCenter(myLatLng);
            map.setZoom(17);

        }
      </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div style="width: 600px; height: 400px; float:left;">
        <div id="map-canvas" style="width: 100%; height: 100%;">
        </div>
    </div>
    <div style="float:right;">
        <div id="Div1" style="width: 100%; height: 100%; text-align:left; padding:20px;">
            <asp:Button ID="Button1" runat="server" Text="Zoom The Marker" OnClientClick="getInfo();return false;" />
        </div>
    </div>
</asp:Content>

The Output 

Before Zoom

After Zoom


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Friday, 3 January 2014

Disable Back Browser Button in web Page

Leave a Comment
This example will show how to disable Back button in your browser. To achieve this objective, the javascript will be use to redirect back to the current page if the user click on the browser back button and give message to user. So let see the example.

I'll set the script at HEAD element and use onpageshow and  onload event in the body element.

The Javascript put in Head element

<script type="text/javascript">
        window.history.forward();
        function noBack() { window.history.forward(); document.getElementById("Message").innerHTML = "You cannot Go Back"; }
    </script>


The Html/Aspx/Jsp page

:
: Head element 
: 

<body onpageshow="if (event.persisted) noBack();" onload="noBack();" >

:
: body content

 <div id="Message" style="color:red;">
 </div>

:
:
</body>
</html>


The Output

If the user click on the browser back button, the script will automatically redirect to the current page and give the message "You cannot go back" to user


Note : You can customize the script for example if you want to force logout user if user click on the back button, you can create one page "forceLogout.aspx"  and then edit the script to redirect page to forceLogout.aspx . So everytime user click on the browser back button , user will redirect to forceLogout.aspx page.

By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Monday, 16 December 2013

How to read XML file in PHP

Leave a Comment
 In this example show how to read xml file in PHP. Let say the XML file is like this :

<?xml version="1.0" encoding="utf-8"?>
<database>
<config userdb="custinfosys" dbpass="P@ssw0rd" host="localhost:3306" database="customerinfosys"/>
<defaultPassword></defaultPassword>
</database>


So i want to read config element and all of the attribute . Here is a sample code to read xml file :

PHP -> read XML File :

        //declare DOMDocument
        $objDOM = new DOMDocument();

        //Load xml file into DOMDocument variable
        $objDOM->load("../configuration.xml");

        //Find Tag element "config" and return the element to variable $node
        $node = $objDOM->getElementsByTagName("config");

        //looping if tag config have more than one
        foreach ($node as $searchNode) {
            $dbHost = $searchNode->getAttribute('host');
            $dbUser = $searchNode->getAttribute('userdb');
            $dbPass = $searchNode->getAttribute('dbpass');
            $dbDatabase = $searchNode->getAttribute('database');
        }


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Sunday, 15 December 2013

How to execute sql query statement in PHP

Leave a Comment
We have learn how to create connection and select database in PHP, now i will show how to run query in php.

we will use "mysqli_query" or "mysql_query " method to run the query in php.
Assume we already have connection and already select the database in PHP, here is a example to run the query statement.

NOTE : Refer both post above to create connection and select database

The Database Table

CREATE TABLE IF NOT EXISTS `users` (
  `userid` varchar(40) NOT NULL,
  `password` varchar(80) NOT NULL,
  `ROLES` varchar(40) NOT NULL,
  PRIMARY KEY (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`userid`, `password`, `ROLES`) VALUES
('developersnote', 'P@ssw0rd', 'ADMIN');


The code

<?php

require_once('DbUtility.php');
$dbClass = new DbUtility();
$db = $dbClass->getDbConnectionMySQLi();

if (mysqli_connect_errno($db)) {
    $error = '<p><br />Failed to Connect to Database' . mysqli_connect_error();
} else {
    $dbClass->setDatabaseMySQLi($db);
    $strsql = "SELECT * FROM users where userid='developersnote' AND password='P@ssw0rd'";
    $dbComm = mysqli_query($db, $strsql);
    $num_rows = mysqli_num_rows($dbComm);
    if ($num_rows > 0) {
        session_start();
        $row = mysqli_fetch_array($dbComm);
        $_SESSION["LOGINID"] = 'developersnote';
        $_SESSION["ROLES"] = $row["ROLES"]; //read value from column ROLES in query result
        
        //header("Location: ../secure/defaultPage.php"); //redirect to default page..but i will echo successful message
        echo 'Successful';
    } else {
        echo "Is Either Username or password was wrongly entered : " . mysqli_error($db);
    }
}
?>



By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Select Database in PHP Example

Leave a Comment
This post is a extended from previous post. Read previous here

This example show how to select database schema / name in database MySQL :

The DbUtil Class

<?php

final class DbUtility {
    
    public static $dbHost ;
    public static $dbUser ;
    public static $dbPass ;
    public static $dbDatabase ;

    public function __construct() {  
        self::$dbHost = "localhost:3306";
        self::$dbUser = "custinfosys";
        self::$dbPass = "P@ssw0rd";
        self::$dbDatabase = "customerinfosys"; // database 
    }

    public static function getDbConnectionMySQL() {       
        return mysql_connect(self::$dbHost, self::$dbUser, self::$dbPass); //Connect to the databasse         
    }
    public static function getDbConnectionMySQLi() {       
        return mysqli_connect(self::$dbHost, self::$dbUser, self::$dbPass); //Connect to the databasse         
    }
    
    public static function setDatabaseMySQL($db){              
        mysql_select_db($db,self::$dbDatabase) or die("Couldn't select the database.");
    }
    
    public static function setDatabaseMySQLi($db){              
        mysqli_select_db($db,self::$dbDatabase) or die("Couldn't select the database.");
    }    
    

}
?>


How to use Example

1. Create php file name index to test the class
2. copy paste this code and try to run in browser using xamp / any web server install with php

<?php

require_once('DbUtility.php');
$dbClass = new DbUtility();
$db = $dbClass->getDbConnectionMySQLi();
if (mysqli_connect_errno($db)) {
    echo '<br/>Failed to Connect to Database' . mysqli_connect_error();
} else {
    echo '<br/>successfully create connection with "mysqli_connect"';
    $dbClass->setDatabaseMySQLi($db);
    echo '<br/>successfully set database with "mysqli_select_db"';
}

$db1 = $dbClass->getDbConnectionMySQL();
if (mysql_error($db1)) {
    echo '<br/>Failed to Connect to Database' . mysql_error();
} else {
    echo '<br/>successfully create connection with "mysql_connect"';
    $dbClass->setDatabaseMySQL($db1);
    echo '<br/>successfully set database with "mysql_select_db"';
}
?> 

The Output


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

How to create mysql connection in php

Leave a Comment
 The example will show how to create connection to MySQL database using "mysql_connect" or "mysqli_connect" . The mysql_connect has been deprecated. Read here for more information.

The  DbUtil Class

<?php

final class DbUtil {
    
    public static $dbHost ;
    public static $dbUser ;
    public static $dbPass ;


    public function __construct() {  
        self::$dbHost = "<host name>";
        self::$dbUser = "<user name db>";
        self::$dbPass = "<pasword db>";
        }

   public static function getDbConnectionMySQL() {     
        return mysql_connect(self::$dbHost, self::$dbUser, self::$dbPass); //Connect to the databasse        
    }
    public static function getDbConnectionMySQLi() {      
        return mysqli_connect(self::$dbHost, self::$dbUser, self::$dbPass); //Connect to the databasse        
    }




?>


How to use Example

1. Create php file name index to test the class
2. copy paste this code and try to run in browser using xamp / any web server install with php

<?php

require_once('DbUtility.php');
$dbClass = new DbUtility();
$db = $dbClass->getDbConnectionMySQLi();
if (mysqli_connect_errno($db)) {
    echo '<br/>Failed to Connect to Database' . mysqli_connect_error();
} else {
    echo '<br/>successfully create connection with "mysqli_connect"';
}

$db1 = $dbClass->getDbConnectionMySQL();
if (mysql_error($db1)) {
    echo '<br/>Failed to Connect to Database' . mysqli_connect_error();
} else {
    echo '<br/>successfully create connection with "mysql_connect"';
}
?>

The Output



By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Saturday, 23 November 2013

Simple Image Galery in PHP - Example

Leave a Comment
This post is a different from others post. because in this example i will use PHP language to create very simple Image Galery.

The code will get list from image directory, and the build a image tag element in html to show the image. Very simple.

Lets see the example.

The  Project list Folder and file



The PHP File 

<html>
    <body>        
        <h1>Image Gallery</h1>        
        <div style="width:640px;">
            <?php 
            //change directory to image stored location
            //if image is at another server try to do like this 
            //$dir = 'http://<server ip address>/<location at server>'
            //make sure image is accessible
            $dir    = 'Images';
            $files1 = scandir($dir);           
            
            foreach ($files1 as $value) {
                if(strtoupper(explode('.', $value)[1]) == "JPG"){//make sure image is JPG or just remove this filter                                   
                    echo "<img src=\"";
                    echo $dir ;
                    echo "\\";
                    echo $value ;
                    echo "\" width=\"200px\" ";
                    echo "height=\"200px\" ";
                    echo " />";
                    echo "<br/>";                           
                }
            }
            ?>
        </div>        
    </body>    
</html>

The Output



By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.