Posts

Showing posts with the label PHP

Arranging DIVs Horizontally

Image
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:...

Google Map API Zoom The Marker Example

Image
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);      ...

Disable Back Browser Button in web Page

Image
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 a...

How to read XML file in PHP

 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");       ...

How to execute sql query statement in PHP

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...

Select Database in PHP Example

Image
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 t...

How to create mysql connection in php

Image
 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        ...

Simple Image Galery in PHP - Example

Image
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://...