Translate

Thursday, 17 July 2014

Using Ajax Categories and their Sub Categories and Sub Sub Categories display

Index.php:


 <html>
<body>
 <form id="custom" method="post" name="form" enctype="multipart/form-data">
   <fieldset title="Location Information" >
   <legend></legend>
    <label>catgories</label>
    <select name="main_id" onchange="showCustomer(this.value)">
   <option value="" class="search"><---Select the catagoeris--> 
   </option>                               
      <?php 
 $sel1=mysql_query("select * from categories order by cat_name asc");
  while($cat=mysql_fetch_array($sel1))
   {         
 $cat_id=$cat['cat_id']; 
 $cat_name=$cat['cat_name'];                                           
 <option value="<?php echo $cat_id; ?>"><?php echo $cat_name; ?></option>
<?php } ?>
 </select>
 <label>Sub Catgories</label>
  <p id="txtHint">
  <select name="sub"  onchange="show(this.value)">
    <option value=""><---Select sub catagoeris--></option>
   </select>
     </p>
    <p id="sub_sub"> 
  <select  name="sub_sub">
   <option value=""><--Select name--></option>
   </p>
 </body>
</html>


ajax.php:


<?php
include("conn.php");
?>
<?php if(isset($_GET['q'])) 

{

$id1=$_GET['q'];

?><p>
      <select  onchange="show(this.value)" name="sub">
      <option value=""><--Select--></option>
      <?php
      $select1=mysql_query("select * from sub_categories where cat_id='$id1'");
      while($menu2=mysql_fetch_array($select1))
      {
      ?>
      <option value="<?php echo $menu2['sub_cat_id'];?>"> <?php echo $menu2['sub_cat_name'];?></option>
      <?php
      }

      ?>
      
      </select> 
       
      </p>
     <?php
     }
     if(isset($_GET['s'])) 

{

$id3=$_GET['s'];

              $sub_sub_cat=mysql_query("select * from sub_sub_categories where sub_cat_id='$id3'") or die(mysql_error());
             if(mysql_num_rows($sub_sub_cat)=="")
             {
                 
             }
    
       else
      {
          ?>
     <p> 
     
   
      <select  name="sub_sub">
      <option value=""><--Select name--></option>
      <?php
      $select2=mysql_query("select * from sub_sub_categories where sub_cat_id='$id3'");
      while($menu3=mysql_fetch_array($select2))
      {
      ?>
      <option value="<?php echo $menu3['id'];?>"> <?php echo $menu3['sub_sub_cat_name'];?></option>
      <?php
      }
      
      ?>
      
      </select>
      </p>
      
     <?php  }} ?> 
     



ajax script:(script1)


<script>
        function showCustomer(str)
        {
        var xmlhttp;    
        if (str=="")
          {
          document.getElementById("txtHint").innerHTML="";
          return;
          }
        if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
          }
        else
          {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        xmlhttp.onreadystatechange=function()
          {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
            }
          }
        xmlhttp.open("GET","ajax.php?q="+str,true);
        xmlhttp.send();
        }
        </script>

ajax script:(script2)


<script>

        function show(str)
        {
        var xmlhttp;    
        if (str=="")
          {
          document.getElementById("sub_sub").innerHTML="";
          return;
          }
        if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
          }
        else
          {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        xmlhttp.onreadystatechange=function()
          {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            document.getElementById("sub_sub").innerHTML=xmlhttp.responseText;
            }
          }
        xmlhttp.open("GET","ajax.php?s="+str,true);
        xmlhttp.send();
        }
        </script>  


This Coding is used for categories and their sub categories and sub sub categories.If we click on category and it display their that particular categories types and also that sub category you click that particular sub sub categories types also displayed.The script1 is used for to display the sub category and script2 is used for to display the sub sub categories.I hope this very useful for you.

db screenshot:category


sub category:






Thursday, 10 October 2013

PHP Server Variable using foreach Condition

index.php:

<?PHP

foreach($_SERVER as $key_name => $key_value) {

print $key_name . " = " . $key_value . "<br>";

}

?>
 
In this coding foreach Condition is used to which Browser the user is to working and 
which remote address &IP address all information is to be display. 

Wednesday, 9 October 2013

Server Variables in PHP to find the Referrer,Browser&IP Address

Coding:

<?php
$referrer = $_SERVER['HTTP_REFERER'];
$browser = $_SERVER['HTTP_USER_AGENT'];
$ipAddress = $_SERVER['REMOTE_ADDR'];

print "Referrer = " . $referrer . "<BR>";
print "Browser = " . $browser . "<BR>";
print "IP Adress = " . $ipAddress;
?>
 
In the above coding is usefull to find out which browser the user is to be working 
on&which ip address&which referrer (i.ein which domin&folder the user is working).
Try this Script. 

Tuesday, 8 October 2013

Trim Function Coding

Coding:

<?PHP

//$space = "creatersite";
$space = trim(" hello ");//trim() is to remove space
$letCount = strlen($space);
print $letCount;

?>
 
In this Coding why we have to use trim function to remove the space between the letters
and characters 
$space = trim(" hello ");
We didn't use the trim function we can see that there is extra space before and after 
the text take and count the length.$space = "creatersite";
Try this script 

Sunday, 6 October 2013

To View PDF File in Lightbox Using CSS&Javascript

Screenshot:
                                       
Explanitation:
                                         In this concept Like an Light box only.In Light box concept if u click an option that image will be viewed zoom that image.Likewise in the same concept i'll give coding for to view/display the PDF File in an lightbox concept.

index.php:

<html>
<link href="style2.css" rel="stylesheet"/>
<link href="style1.css" rel="stylesheet"/>
<script type="text/javascript" src="j.js"></script>
<script type="text/javascript" src="j1.js"></script>
</head>
<body>
<a style="width:144px;" href="parameters1.pdf" id="fb_26" class="demo" data-fb-options="className:floatbox;caption:href;">
<img id="fb_27" class="plain" src="pdf_108.jpg" alt="" height="108" width="144"></a>
</body>
</html>

Download CSS:style1.css,style2.css
Download js :j.js,j1.js

Thursday, 3 October 2013

Onload pointer in field using Javascript

Screenshot:

                                                
index.php:

<body id="bdy" onload="document.contactform.name.focus();"></body>
contactform-->formname,
name-->fieldname


onload="document.contactform.name.focus();" we have to put this coding in inside the <body>tag.
contactform-->formname
name       -->fieldname      

Innerhtml Validation for a Form

Screenshot:
                       
index.php:

<form name="form1" method="post" onsubmit="return validation();">
<table width="30%" border="0" cellspacing="0" cellpadding="5" id="tbl">
  <tr>
    <td width="226" scope="col"><label for="first3">Firstname</label></td>
    <td width="248" scope="col"><input type="text" name="first" id="first3" /></td>
   <td width="30%" id="fname"></td>
  </tr>
  <tr>
    <td width="226" scope="col"><label for="last"> Lastname</label></td>
    <td width="248" scope="col">  <input type="text" name="last" id="last" /></td>
    <td width="30%" id="lname"></td>
  </tr>
  <tr>
    <td align="center" colspan="2"><input type="submit" name="submit" id="submit" value="Submit" /> </td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>

validation.js:


function validation()
{

var nae=document.form1.first.value;
    if(nae=="" || nae=="null") 
    {
        document.getElementById('fname').innerHTML="Enter Firstname";
        document.getElementById('lname').innerHTML="";
        
        document.form1.first.focus();
        return false;
    }
    
    var nme=document.form1.last.value;
    if(nme=="" || nme=="null") 
    { 
        document.getElementById('fname').innerHTML="";
        document.getElementById('lname').innerHTML="Enter Lastname";
        
        document.form1.last.focus();
        return false;
    }
}