Wednesday, May 2, 2012

Beginning Object Oriented Programming | Part 1

What Is OOP System.

Object Oriented Programming Language is basically a set of rules and concepts which makes it easy to understand and manage. Class's , inheritances , constructor, destructor, abstractor class are the concept provided by OOPS.

Class :- 
        In case of OOPS a Class is a collection of Data Member (Variables, Properties ) and  Member Function (Called Function or Methods). Data members are used to store the Information where member function are used to operate the Data Member's. In case of  PHP member of classes have friendly accessifier , however one can define the explicitly with one of the these Access- modifier:-
  1. Private :- The members which one defined  as private keyword , only accessible within the class, No one can access them outside of the Class , even Object of the Class.
  2. Public:- The member which one are defined as  Public Keyword can be accessed within  a Class and outside of the Class. Those member function can be accessed with object of that class or with class name depends upon access-modifier. 
  3. Protected:-   Protected member function like as private member but protect functions  can be inherited one level down while private are not.
Syntax For the Class :-


class <class name >
{
Public $datamember; // In this section we can defile data member as Private, Public or Protected.

public function <function name(method)>
               {
          //code to operate the data member's goes here.
               }



}



To be Continued .........Objects

Tuesday, May 1, 2012

jQuery Selectors

jQuery Selectors

Here are some great and easy jquery selector .

1: How to find all the the elements of a web Page.


<script type="text/javascript">

// ('*') is used for all the element of a web page.


var count=$('*').length;
alert(count);

// ('p') It will count all the P tag of a web page.

var count=$('p').lenght;
alert(count);



// ('#idname') It will count all the tag within this element. For example #idname is a div and have 4 element //inside it. then this selector will count element inside this only.


var count=$('#idname').lenght;
alert(count);



</script>


Saturday, April 21, 2012

Creating Pyramid using php | php tutorial

Here is a php Script to create Simple Pyramid using php Script.


$n=9;
for($i=0; $i<=$n; $i++)
{

for($j=1; $j<=$i; $j++)

echo "&nbsp;";


for($k=1; $k<=$n-$i; $k++)

echo $k;


for($j=($k-2); $j>0; $j--)

echo $j;





for($k=1; $k<=$i; $k++)

echo "&nbsp;";






echo "</br>";

}





?>



The Above Code will Create the result below.:--

                1               
              121             
            12321           
          1234321         
        123454321       
      12345654321     
    1234567654321   
  123456787654321 
12345678987654321


Check More PhP tutorial Here:- Online php tutorial

Friday, April 20, 2012

Simple Form Validation Using jQuery

*********************
Form Validation Using jQuery
*******************
*******
***
*

Here is the Step by Step tutorial for validating contact or any other type of form using simple jQuery.


Step 1: First of all we need a contact form or any other form you want to validate :-

Here is the Code for the simple form using all Character , number , email and Web url s to validate.

It's a Very Simple form Created in Dreamweaver using table just to check the functionality.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>


</head>

<body>
<form action="" method="get" id="form1" name="form1">
<table width="60%" border="1" >
<tr>
<th scope="row">First Name</th>
<td><label>
<input type="text" name="txtfname" id="txtfname" class="required" />
</label></td>
</tr>
<tr>
<th scope="row">Middle Name</th>
<td><input type="text" name="txtmname" id="txtmname" class="required"/></td>
</tr>
<tr>
<th scope="row">Last Name</th>
<td><input type="text" name="txtlname" id="txtlname" class="required"/></td>
</tr>
<tr>
<th scope="row">Phone No</th>
<td><input type="text" name="txtphno" id="txtphno" class="required number" /></td>
</tr>
<tr>
<th scope="row">Email</th>
<td><input type="text" name="txtemail" id="txtemail" class="required email"/></td>
</tr>
<tr>
<th scope="row">Age</th>
<td><input type="text" name="txtage" id="txtage" lass="required number"/></td>
</tr>
<tr>
<th scope="row">Address</th>
<td><input type="text" name="txtaddress" id="txtaddress" /></td>
</tr>
<tr>
<th scope="row">Web Url</th>
<td><input type="text" name="txturl" id="txturl" class="url"/></td>
</tr>
<tr>
<th scope="row"><label>
<input type="submit" name="button" id="button" value="Submit" />
</label></th>
<td>&nbsp;</td>
</tr>
</table>

</form>

</body>
</html>

The table looks like this:



Now All we Need to Include jQuery file in this file at the head Section where usually all the script and style are written. There are lot's of jquery scripts online which you can use. I have one for this task and it's working with my code.

Here is the 2nd step to include jquery Script in the web page:
<script type="text/javascript" src="JQuery/jquery-latest.js" language="javascript"></script>
<script type="text/javascript" language="javascript" src="JQuery/jquery.validate.js"></script>

All what you need to add these line in your head section of form page. You may have different path for these file so you need to define the file path yourself. And the most important thing if you are getting 2 or more then 2 files for the jQuery then please read the instruction about the file sequence that how those files must be added. As in my case I add the query-latest.js after jquery.validate.js then my code will not work.

And now all we need to add java script code after those .js files we already have added.
<script type="text/javascript">
$(document).ready(function()

{
$("#form1").validate()
});


</script>



Now all what you need to do is test if the jQuery is working or not. For that you must add a class to to input tag for which you want to use validation. If the input value is required then then you need to put a class="required" to that input tag.


Like:
if the First Name is required then add class="required" and if the tag is to input a number then class="number" , class="email" and class="url". As jQuery checks for the class and applies the query to that tag's value.

If the tag is required and must be number, email or url etc. Then class will be :
class="required number" , class="required email". Hope you have got the idea.

Note:-
I already have added a class attribute for all the input tag on the form as i don't want to paste all the code again in here in Blog.

Here you can download the jQery files. Form Validation jQuery

Tuesday, April 17, 2012

Creating a Admin Login form


Here is the Example of Admin Login form psd file:












Here is the Html and Css Code for the login form:







<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
* {
margin:0px;
padding:0px;}

fieldset {
width:575px;
height: 335px;
margin: auto;
background:url(images/bg_02.png) repeat-x;
border:none;
position:relative;
margin-top: 150px;
border: 1px solid #d6d6d6;
}
div {
width:356px;
height:180px;
margin:119px 0px 0px 112px;
position:absolute;

}

input {
width: 356px;
height: 48px;
border:none;
margin-bottom:18px;
border-radius: 4px;
color:#fff;
padding-left:10px;
background-image:url(images/man_03.png) no-repeat;
background: #000;}

button {
width:96px;
height: 40px;
font-weight:bold;
}

.forgot {
float: right;
font-weight:bold;
}

h3 {
font-size: 50px;
font-family:"Monotype Corsiva", cursive;
position:absolute;
margin:37px 0px 0px 118px;
color:red;
}

.erroruname {
width:48px;
height:41px;
background:url(images/Login-page-templates_03.png)no-repeat;
position:absolute;
float:left;
margin:-82px 0px 0px 346px;
}

.erroruname img {
position:absolute;
margin:33px 0px 0px -14px;
}

.errorpass {
width:48px;
height:41px;
background:url(images/Login-page-templates_06.png)no-repeat;
position:absolute;
float:left;
margin:-82px 0px 0px 346px;
}

.errorpass img {
position:absolute;
margin:33px 0px 0px -9px;
}

</style>

</head>

<body>
<form id='login' action='login.php' method='post' accept-charset='UTF-8'>
<fieldset>
<h3>Admin Login Here</h3>
<div>

<p>
<input type="text" id="username" name="username" value="User Name" />
<span class="erroruname"><img src="images/man_03.png" alt="user" /></span>
</p>
<p>
<input type="password" id="password" name="password" value="password" />
<span class="errorpass"><img src="images/Login-page-templates_07.png" alt="user" /></span>
</p>
<p><label><button>Login ></button></label> <span class="forgot">Forgot Password ?</span>

</p>
</div>

</fieldset>
</form>


</body>
</html>

Monday, April 16, 2012

Creating Drop Down List/Menu with Ajax and PhP

Here is all Codes below to show the full tutorial to create a Drop/Down List menu item with Ajax and PhP. All what you need at least Wamp server or any other compatible to your operating system. I will provide on main php file which will have Html code and some php on it. Second will the code.php and third will be the SQL database and with all dummy data installed on but if you have knowledge in php and mysql you can your self create database and tables on it.

Here is the preview for the tutorial:



Here is the Code for first php file below:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function Action(link,md)
{

var obj,url;

url="dcode.php?mode="+md+"&id="+link+"&r="+Math.random();

try {
obj=new XMLHttpRequest();
}
catch(e)
{
try {
obj=new ActivexObject("Microsoft.XMLHTTP");

}

catch(e) {

alert(e);

}

}

obj.open("GET",url,true);
obj.send(null);
obj.onreadystatechange=function()
{
if(obj.readyState==4)
{


var res=obj.responseText;
if(md=='city')
{
document.getElementById("market").innerHTML=res;
}
else {
document.getElementById("city").innerHTML=res;

}
}

}

}
</script>

</head>

<body>

<form action="" method="get">
<table width="200" border="1" align="center">
<tr>
<th scope="row"><label>
<select name="state" id="state" style="width:150px;" onchange="Action(this.value,'state')">

<?
mysql_connect("localhost","root","") or die("check server");
mysql_select_db("students")or die("check database");

$str="select sno,sname from state";
$rs=mysql_query($str);

while(list($scode,$stname)=mysql_fetch_array($rs))
{

echo "<option value='$scode'>$stname</option>";

}
?>
</select>
</label></th>
</tr>
<tr>
<th scope="row"><label>
<select name="city" id="city" style="width:150px;" onchange="Action(this.value,'city')">


</select>
</label></th>

</tr>

<tr>
<th scope="row"><select name="market" id="market" style="width:150px;">

</select></th>
</tr>

</table>
</form>

<script type="text/javascript">
Action(101,'state');
</script>
</body>
</html>




Here is the code file below:




<?


mysql_connect("localhost","root","") or die("check server");
mysql_select_db("students")or die("check database");



if($_REQUEST["mode"]==state)

{
$id=$_REQUEST["id"];

$str="SELECT citycode,cityname
FROM city
WHERE statecode
IN (

SELECT statecode
FROM city
JOIN state ON city.statecode = $id)";

$rs=mysql_query($str);

while(list($citycode,$cityname)=mysql_fetch_array($rs))
{
echo "<option value='$citycode'>$cityname</option>";

}

}


if($_REQUEST["mode"]==city)

{
$cid=$_REQUEST["id"];
$str="SELECT mcode,mname
FROM market
WHERE citicode
IN (

SELECT citicode
FROM market
JOIN city ON market.citicode = $cid)";
$rs=mysql_query($str);

while(list($mcode,$mname)=mysql_fetch_array($rs))
{
echo "<option value='$mcode'>$mname</option>";

}




}

?>







here is the simple database created by me:






-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 16, 2012 at 07:27 PM
-- Server version: 5.1.36
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `students`
--

-- --------------------------------------------------------

--
-- Table structure for table `city`
--

CREATE TABLE IF NOT EXISTS `city` (
`Citycode` int(10) NOT NULL AUTO_INCREMENT,
`statecode` int(10) NOT NULL,
`Cityname` varchar(20) NOT NULL,
PRIMARY KEY (`Citycode`),
UNIQUE KEY `Cityname` (`Cityname`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=211 ;

--
-- Dumping data for table `city`
--

INSERT INTO `city` (`Citycode`, `statecode`, `Cityname`) VALUES
(201, 101, 'Ludhayana'),
(202, 101, 'Jalander'),
(203, 102, 'Kullu'),
(204, 102, 'Mandi'),
(205, 102, 'Shimla'),
(206, 103, 'Pkl'),
(207, 103, 'Ambala'),
(208, 101, 'Amritsar'),
(209, 104, 'Itawa'),
(210, 105, 'mumbai');

-- --------------------------------------------------------

--
-- Table structure for table `market`
--

CREATE TABLE IF NOT EXISTS `market` (
`mcode` int(10) NOT NULL AUTO_INCREMENT,
`citicode` int(10) NOT NULL,
`mname` varchar(20) NOT NULL,
PRIMARY KEY (`mcode`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;

--
-- Dumping data for table `market`
--

INSERT INTO `market` (`mcode`, `citicode`, `mname`) VALUES
(1, 201, 'Shiv Chock'),
(2, 201, 'Samrala Chock'),
(3, 202, 'Rama mandi'),
(4, 202, 'JL busstand'),
(5, 203, 'kullu busstand'),
(6, 204, 'indra market'),
(7, 205, 'Lakar bajar'),
(8, 205, 'shimla busstand'),
(9, 206, 'manimazra'),
(10, 207, 'amabala city'),
(11, 208, 'bagha border');

-- --------------------------------------------------------

--
-- Table structure for table `product`
--

CREATE TABLE IF NOT EXISTS `product` (
`Sno` int(11) NOT NULL AUTO_INCREMENT,
`Pname` varchar(50) NOT NULL,
`Price` int(50) NOT NULL,
`Qty` int(50) NOT NULL,
PRIMARY KEY (`Sno`),
UNIQUE KEY `Pname` (`Pname`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=113 ;

--
-- Dumping data for table `product`
--

INSERT INTO `product` (`Sno`, `Pname`, `Price`, `Qty`) VALUES
(101, 'Hard Disk', 100, 3),
(102, 'CD Rom', 39, 4),
(103, 'hdd', 555, 2),
(104, 'cd', 24, 11),
(105, 'flopy', 24, 11),
(106, 'flopys', 24, 11),
(107, 'motherboard', 24, 11),
(108, 'motherboard1', 24, 11),
(109, 'motherboard1d', 24, 11),
(110, 'Processor', 5555, 11),
(111, '', 0, 0),
(112, 'vcv', 0, 0);

-- --------------------------------------------------------

--
-- Table structure for table `state`
--

CREATE TABLE IF NOT EXISTS `state` (
`Sno` int(10) NOT NULL AUTO_INCREMENT,
`Sname` varchar(10) NOT NULL,
PRIMARY KEY (`Sno`),
UNIQUE KEY `Sname` (`Sname`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=105 ;

--
-- Dumping data for table `state`
--

INSERT INTO `state` (`Sno`, `Sname`) VALUES
(101, 'Punjab'),
(102, 'Himachal'),
(103, 'Haryana'),
(104, 'UP');

-- --------------------------------------------------------

--
-- Table structure for table `tbstudent`
--

CREATE TABLE IF NOT EXISTS `tbstudent` (
`Sno` int(10) NOT NULL AUTO_INCREMENT,
`Sname` varchar(50) NOT NULL,
`Sclass` varchar(50) NOT NULL,
`Saddress` varchar(100) NOT NULL,
PRIMARY KEY (`Sno`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=135 ;

--
-- Dumping data for table `tbstudent`
--

INSERT INTO `tbstudent` (`Sno`, `Sname`, `Sclass`, `Saddress`) VALUES
(114, 'Nitesh', '8th', ' #2234'),
(116, 'sanjay', '7th', '#2234 MOh'),
(123, 'reakhes', '12', ' #2234 MOh'),
(120, 'rakesh', '12th', ' maloya'),
(122, 'fgsfgdf', 'gfgsdfg', ' gsdfgsdfg'),
(124, 'anil', '12', ' mohali'),
(125, 'niks', '23', ' #4567'),
(126, 'kiran', '12', ' chd'),
(127, 'joy', '11', ' Usa'),
(128, 'Matt', '12', ' taxes'),
(129, 'nitika', '6th', ' mandi'),
(130, 'arvind', '14th', ' dera bassi'),
(131, 'aman', '12', ' Dhanas'),
(132, 'Pamel', '11th', ' philipins'),
(133, 'Rashad ', '3rd', ' bangladesh'),
(134, 'vinci ', '2nd', ' philipins');






After Working with these file you will get a completed tutorial for Ajax and php Drop Down menu. This project have still some bugs , i am still working on it and will be updating it.