Sunday, 26 May 2013

Apply active class on menu using php

When a menu item is clicked and is active, what's the best way to style it differently? Lets create a dynamic menu bar with the help of php.

Step 1:Create a html page with menu items

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Html,Css,Php Menu</title>
<style type="text/css"> li{
    float: left;
    padding: 0 4px 0 0;}

/*  create active class that are used when menu is clicked */

    background: none repeat scroll 0 0 #636363;
    border-color: #636363 #636363 -moz-use-text-color;
    border-style: solid solid none;
    border-width: 1px 1px medium;
    color: #FFFFFF;


<div class="menu">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About Us</a></li>
<li><a href="contact.html">Contact Us</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="blog.html">Blog</a></li>


Step 2: Create some php code that are usen in header


$directoryURI = $_SERVER['REQUEST_URI'];
$path = parse_url($directoryURI, PHP_URL_PATH);
$components = explode('/', $path);

// this give value in array we take first value because on array 0 wiil contain your domain name
 $first_part = $components[1];

Step 3: Now apply php code in html menu bar

<div class="menu">
<li><a class="<?php if ($first_part=="
index.html") {echo "active"; } ?>" href="index.html">Home</a></li>
class="<?php if ($first_part=="about.html") {echo "active"; } ?>" href="about.html">About Us</a></li>
class="<?php if ($first_part=="contact.html") {echo "active"; } ?>" href="contact.html">Contact Us</a></li>
class="<?php if ($first_part=="services.html") {echo "active"; } ?>" href="services.html">Services</a></li>
class="<?php if ($first_part=="
blog.html") {echo "active"; } ?>" href="blog.html">Blog</a></li>

Copy and paste this div into your page where you create html menu.

Thursday, 16 May 2013

My first poem

Mere kano m kuch aahat si hui mere kano m kuch aahat si hui so ke mai jaga uth ke mai bhaga dekha to wo angadai le rhi thi

Sunday, 12 May 2013

Pagination using php

Pagination is used when number of rows are maximum then these rows are divided into pages.
pagination is the important part of web development.(pagination in php,how to apply pagination in table using php)
Now lets try


       //connect to database
       // now start with query
               $rs=mysql_query("select * from table_name");

       //how many rows  you wants to show in one page. define a variable limit

      //how many rows are fetch into database.

      //check if pages are in float then add 1
} // end if

       // page is variable that contain page number
$page=(isset($_GET['page']))?(int) $_GET['page']:1;
$start =($page==1)?0:($page - 1) * $limit;

       //again apply query using limit

              $rs=mysql_query("select * from table_name  limit $start,$limit");


     //show data into table
   echo "<table><tr>";
   echo "<td>".$row["id"]."</td>";
           echo "<td>".$row["name"]."</td>";
                   echo "</tr></table>";

      //start a loop using variable $i
               for($i=1;$i<=$totalPages;$i++) { 
                   <a href="<?php echo "page_name.php?page=$i" ?>" title=""><?php echo $i;  ?></a>

      <?php }  ?>

Saturday, 4 May 2013

Replace whitespace of string into dash or comma using php

Replaceing  whitespace into dash or comma this problem face by the beginners of we try to solve this problem using php function.( whitespace in string,remove space from string.replace comma and dash place of whitespace.)


Exampal: First of all we take a string

          // create php variable $str
          $str="This is only for test";
         // now set this string in str_replace
         $string=str_replace(" ","-",$str) ;
          echo $string;