Saturday 17 March 2012

Creating Menu Using PHP and html & Highlight current page

very simple to create menu using php. just follow the below step and you are done.


















To create menu with this example you need to define all the page with the following :


say for example your are in the home page


<?php define('THIS_PAGE', 'Home'); ?>


define all pages with define() php function
Now create one menu.inc file :


<style>
.siteNav { padding: 0; margin: 0; }
.siteNav ul { margin: 0; padding: 0; }
.siteNav li { margin: 0; padding: 0; display: block; float:left; text-align: center; }
.siteNav a { background:url(images/navbuttongreen.gif) no-repeat; color : #fff; text-decoration: none; font-weight: bold; display: block; height: 26px; width: 94px; line-height: 26px; }
.siteNav ul li a:visited { background:url(images/navbuttongreen.gif) no-repeat 0px 0px; color: skyblue; height: 26px; width: 94px; line-height: 26px; }
.siteNav ul li a:hover { background:#F87B27; color: #fff; height: 26px; width: 94px; line-height: 26px; }
.siteNav ul li a:active { background:url(images/navbuttongreen.gif) no-repeat 0px 0px; color: lime; height: 26px; width: 94px; line-height: 26px; }
 
#sectionhome #menuhome a,
#sectionabout #menuabout a,
#sectionservices #menuservices a
{ background:url(images/navbuttonorange.jpg) no-repeat 0px 0px; color: lime; height: 29px; width: 94px; line-height: 29px; padding-top: 0px; margin-top: -3px; cursor: default; }

</style>

<?php
define('THIS_PAGE', 'pagename');
 
$menuitem1 = '<a href="highlighthome.php">Home</a>';
$menuitem2 = '<a href="highlightabout.php">About Us</a>';
$menuitem3 = '<a href="highlightservices.php">Services</a>';
 
switch (THIS_PAGE) {
 
case 'Home':
$menuitem1 = '<a style="background: #1A4572 url(current.jpg) no-repeat top left; color: #fff; height: 29px; width: 94px; line-height: 29px; padding-top: 0px; margin-top: -3px; cursor: default;" href="#nogo">Home</a>';
break;
 
case 'About':
$menuitem2 = '<a style="background:#1a4572 url(current.jpg) no-repeat top left; color: #fff; height: 29px; width: 94px; line-height: 29px; padding-top: 0px; margin-top: -3px; cursor: default;" href="#nogo">About Us</a>';
break;
 
case 'Services':
$menuitem3 = '<a style="background:#1A4572 url(current.jpg) no-repeat top left; color: #fff; height: 29px; width: 94px; line-height: 29px; padding-top: 0px; margin-top: -3px; cursor: default;" href="#nogo">Services</a>';
break;
 
default:
break;
}
 
echo '<ul>
<li>'.$menuitem1.'</li>
<li>'.$menuitem2.'</li>
<li>'.$menuitem3.'</li>
</ul>';
?>


Create pages like highlighthome.php, highlightservices.php, highlightabout.php 


highlighthome.php :



<html>
<head><title>Home</title></head>
<body style="background:#1a4572">
    <div class="siteNav noborder">
           <?php
                  define('THIS_PAGE', 'Home');
                  include('menu.inc');
           ?>
     </div>
</body>
</html>
highlightabout.php :


<html>
<head>
</head>
<body style="background:#1a4572">
    <div class="siteNav noborder">
           <?php
                  define('THIS_PAGE', 'About');
                  include('menu.inc');
           ?>
     </div>
</body>
</html>


highlightservices.php

<html>
<head><title>Home</title></head>
<body style="background:#1a4572">
    <div class="siteNav noborder">
           <?php
                  define('THIS_PAGE', 'Services');
                  include('menu.inc');
           ?>
     </div>
</body>
</html>

Thursday 8 March 2012

HTTP FORM POST in PHP using AJAX


This example demonstrates HTTP FORM POST complete HTML form to the server and displaying the response using AJAX.

HTML Page
<html>
<head>
<title>PHP using AJAX</title>
<script type="text/javascript">
 
var time_variable;
 
function getXMLObject()  //XML OBJECT
{
   var xmlHttp = false;
   try {
     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
   }
   catch (e) {
     try {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
     }
     catch (e2) {
       xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
     }
   }
   if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
     xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
   }
   return xmlHttp;  // Mandatory Statement returning the ajax object created
}
 
var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object
 
function ajaxFunction() {
  var getdate = new Date();  //Used to prevent caching during ajax call
  if(xmlhttp) {
   var txtname = document.getElementById("txtname");
    xmlhttp.open("POST","testing.php",true); //calling testing.php using POST method
    xmlhttp.onreadystatechange  = handleServerResponse;
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send("txtname=" + txtname.value); //Posting txtname to PHP File
  }
}
 
function handleServerResponse() {
   if (xmlhttp.readyState == 4) {
     if(xmlhttp.status == 200) {
       document.getElementById("message").innerHTML=xmlhttp.responseText; //Update the HTML Form element 
     }
     else {
        alert("Error during AJAX call. Please try again");
     }
   }
}
</script>
<body>
<form name="myForm">
<table>
 <tr>
  <td>Enter Name</td>
  <td><input type="text" name="txtname" id="txtname" /></td>
 </tr>
 <tr>
  <td colspan="2"><input type="button" value="Submit" onclick="ajaxFunction();" /></td>
 </tr>
</table>
<div id="message" name="message"></div>
</form>
</body>
</head>
</html>
PHP Code

< ?
 
$a = $_POST['txtname'];
 
echo "Good Morning".$a;
 
 
?>




Explanation for the AJAX Code

Here i have declared 3 JavaScript function:

getXMLObject() – Responsible for creating the AJAX Object depending on the browser

ajaxFunction() – Responsible for calling PHP page through AJAX call
handleServerResponse() – Responsible for displaying the data retrieved from the server

How the AJAX Code Works:
  • When the page loads i am creating an AJAX Object by calling the getXMLObject() function and returning the object created in the xmlhttp variable
  • When the user clicks on the input Button, ajaxFunction() gets called which checks for whether the Ajax Object is created or not and depending on that calls the remote script. Here a function handler handleServerResponse is also defined for retrieving the value from the server
  • When the readystate of the AJAX call reaches 4 and the http status is 200 we pass the data fetched from the server to the textbox

Explanation for the PHP Code

  • I am calling $_POST for fetching the post content send through Ajax Call
  • Finally i am calling echo to send the response back to the calling page

ROUNDED CORNERS AND SHADOWED BOXES


CSS3 will have properties to make rounded borders, borders consisting of images and boxes with shadows, but with some work you can simulate some of them already with CSS2 — and without any tables or extra mark-up.
Of course, rounded borders and shadows will be much simpler with CSS3. For example, to give a paragraph a thick red border with rounded corners, you would need just two lines of CSS3 similar to this:
P { border: solid thick red;
    border-radius: 1em }
And to add a blurry drop shadow half an em below and to the right of the paragraph, just one line would be enough:
P { box-shadow: black 0.5em 0.5em 0.3em }
(You can try here if it works already.) But if you need them now and you don't mind the complexity and lack of flexibility, you can use the technique below. At the very least it will be a nice test for buggy browsers…

FIVE IMAGES ON ONE ELEMENT

The main trick is to use generated content (':before' and ':after') to put four extra images on an element. The ':before' pseudo-element can have a background and a foreground image, the ':after' pseudo-element also, and the element itself can have a background, for a total of five images.
We create five PNG images and put them in the four corners and against the right edge of the element. Here are the images:
top left corner: 
top left corner
top edge and top right corner: 
top right corner
middle part and right edge: 
background and right edge
bottom left corner: 
bottom left corner
bottom edge and bottom right corner: 
bottom and bottom left corner
And here are the CSS rules to position them:
blockquote {
    max-width: 620px;
    background: url(rs-right.png) right repeat-y }
blockquote:before {
    display: block;
    line-height: 0;
    background: url(rs-topright.png) top right no-repeat;
    content: url(rs-topleft.png) }
blockquote:after {
    display: block;
    line-height: 0;
    background: url(rs-bottomright.png) bottom right no-repeat;
    content: url(rs-bottomleft.png) }
Since our background image is 620px wide, we can't allow boxes wider than 620px, without getting gaps. That's why the 'max-width' property is there. The 'display: block' property is needed to make sure the generated content forms boxes of its own above and below the main content, instead of being inserted on the first and last line. The 'line-height: 0' makes sure there is no room for left open for ascenders and descenders above and below the images in the 'content' property.

THE RESULT

And here is how it looks:
Do you see a pale green box with rounded corners and a drop shadow against a white background? If not, your browser isn't handling the generated content correctly (or maybe not at all).
The HTML source is really no more than it should be:
<blockquote>
<p>Do you see a pale green box with rounded corners
and a drop shadow against a white background? If not,
your browser isn't handling the generated content
correctly (or maybe not at all).
</blockquote>

53 CSS-Techniques You Couldn’t Live Without


CSS is important. And it is being used more and more often. Cascading Style Sheets offer many advantages you don’t have in table-layouts – and first of all a strict separation between layout, or design of the page, and the information, presented on the page. Thus the design of pages can be easily changed, just replacing a css-file with another one. Isn’t it great? Well, actually, it is.
Over the last few years web-developers have written many articles about CSS and developed many useful techniques, which can save you a lot of time – of course, if you are able to find them in time. Below you’ll find a list of techniques we , as web-architects, really couldn’t live without. They are essential and they indeed make our life easier. Let’s take a look at 53 CSS-based techniques you should always have ready to hand if you develop web-sitesLinks checked: June/11 2008.
You might want to take a look at the article Powerful CSS-Techniques For Effective Coding.
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
8. CSS Shadows (CSS Shadows Roundup)
CSS-Technique
CSS-Technique
10. Drop Cap – Capital Letters with CSS
CSS-Technique
11. Define Image Opacity with CSS
CSS-Technique
CSS-Technique
CSS-Technique
14.CSS Diagrams
CSS-Technique
CSS-Technique
16. Footer Stick allows for the footer of a Web page to appear either at the bottom of the browser window or the bottom of the Web page content – whichever is visually lowest.
CSS-Technique
CSS-Technique
CSS-Technique

CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
29. CSS-Submit Buttons
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique

CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique
CSS-Technique