Ajax Post data using jQuery

In this tutorial we will see the easy example to post data using jQuery ajax and display them in the same page.
Lets start from the simple css :

#res{
border:solid 1px #000000;
margin:5px;
padding:5px;
width:300px;
visibility:hidden;
}
.error{
color:#FF0000;
}

The First res div used to show the result div when result return. And the second one is used to show error if the user did not enter name.

OK here we write the simple jQuery function, before function include jQuery file:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"> </script>

Now the Function for the data post

<script type="text/javascript">
$(document).ready(function(){
$("#testme").click(function () {
$("#res").css('visibility','visible') ;
$("#res").html('Please wait requesting data...');
$.ajax({
type: "POST",
data: "name=" + $("#name").val(),
url: "taste.php",
success: function(msg){
$("#res").html(msg)
}
});
});
});
</script>

Now create input field with the id name and button to submit id testme because we already have defined them in function that name will be the elementid name and button will be elementid testme.

Enter Your Name : <input id="name" type="text" value="" />
<input type="button" id="testme" value="Send Message"/>

And in the last Create div with the id res because we are getting html return value in res div.

<div id="res">
</div>

The taste.php File:

<?php
if (isset($_POST['name'])) {
$name=$_POST['name'];
if($name!=""){
?>
<p>
<?php echo "Welcome ". $name;?>
</p>
<?php
}else{
?>
<p> Please Enter Your Name</p>
<?php
}
}
?>

Now the Full html code for mainpage:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
#res{
border:solid 1px #000000;
margin:5px;
padding:5px;
width:300px;
visibility:hidden;
}
.error{
color:#FF0000;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"> </script>
<script type="text/javascript">
$(document).ready(function(){
$("#testme").click(function () {
$("#res").css('visibility','visible') ;
$("#res").html('Please wait requesting data...');
$.ajax({
type: "POST",
data: "name=" + $("#name").val(),
url: "taste.php",
success: function(msg){
$("#res").html(msg)
}
});
});
});
</script>
</head>
<body>
Enter Your Name : <input id="name" type="text" value="" /><input type="button" id="testme" value="Send Message"/>
<div id="res">
</div>
</body>
</html>

CSS Centering List Items Horizontally

The CSS :

<style type="text/css">
	body{
		font-family:Arial, Helvetica, sans-serif;
		font-size:14px;
	}
	#menuWrapper{
		width:980px;
		margin:0 auto;
	}
	#topMenu {
		width:980px; 
		background-color:#b6280c; 
		float:left; 
		height:30px;
	}
	#topMenu ul {
		list-style:none;
		margin:7px auto;
		text-align:center;
		width:980px;  
	}
	#topMenu ul li {
		border-right: 1px solid #9F230A;
		cursor: pointer;
		display: inline;
		padding: 0 20px;
		text-align: center;
		width: 120px;
		color:#fea290;
		height:30px;
	}
	#topMenu ul li:hover {
		color:#FFFFFF;
	}
</style>

Now The HTML

<div id="menuWrapper">
    <div id="topMenu">
    	<ul>
        	<li>Home</li>
            <li>Users</li>
            <li>LogOff</li>
        </ul>
    </div>
    </div>

Deleting Multiple Record Using Checkbox with Select All Deselect all option

In this tutorial I am show how to delete multiple records using checkbox. The core part of this tutorial is Looping through the post checkbox value

  $checkbox=$_POST['checkbox'];
  for($i=0;$i
 
Ok Here I begin with simple javascript function to select and deselect all option:
 
The Javascript:
 
<pre lang="LANGUAGE"><script type="text/javascript"><!--mce:0--></script>

The Buttons:

<input onclick="selectAllCheckBoxes('newsadd', 'checkbox[]', true);" type="button" value="Select All" />
<input onclick="selectAllCheckBoxes('newsadd', 'checkbox[]', false);" type="button" value="Clear All" />

Now Create Database Connection:

<!--?php
$dbhost="localhost";
$dbuser="root";
$dbpass="password";
$dbname="databasename";
 
$dbconn=mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
if($dbconn){
mysql_select_db($dbname);
?-->

Create Table For your Test :

CREATE  TABLE  `test`.`tbltest` (
    `sno` INT NOT  NULL  AUTO_INCREMENT  PRIMARY  KEY ,
      `name` VARCHAR( 50  )  NOT  NULL ,
      `address` VARCHAR( 50  )  NOT  NULL ,
      `email` VARCHAR( 50  )  NOT  NULL ) ENGINE  =  MYISAM

Insert some data

INSERT  INTO  `test`.`tbltest` (
`sno` ,
  `name` ,
  `address` ,
  `email` )
VALUES (
NULL ,  'Ram',  'Kathmandu',  'ram@mail.com'), (
NULL ,  'Shyam',  'Kathmandu',  'shyam@mail.com'), (
NULL ,  'Sita',  'Bhaktapur',  'test@sita.com'), (
NULL ,  'Krishna',  'Janakpur',  'kk@mail.com');

Now we will go to html

<form method="post">
<table border="1" cellspacing="0" cellpadding="4">
<thead>
<tr>
<th>Name</th>
<th>Address</th>
<th>Email</th>
<th>&amp;nbsp;</th>
</tr>
</thead>
<!--?php
$q="SELECT * FROM tbltest";
$r=mysql_query($q);
while($row=mysql_fetch_assoc($r)){
?-->
<tbody>
<tr>
<td><!--?php echo $row['name'];?--></td>
<td><!--?php echo $row['address'];?--></td>
<td><!--?php echo $row['email'];?--></td>
<td>
<input id="checkbox[]" name="checkbox[]" type="checkbox" value="&lt;? echo $row['sno']; ?&gt;" /></td>
</tr>
<!--?php
}
?-->
<tr>
<td>&amp;nbsp;</td>
<td colspan="3">
<div>
<input onclick="selectAllCheckBoxes('deleteuser', 'checkbox[]', true);" type="button" value="Select All" />
<input onclick="selectAllCheckBoxes('deleteuser', 'checkbox[]', false);" type="button" value="Clear All" />
<input id="delete" name="delete" type="submit" value="Delete Selected" /></div></td>
</tr>
</tbody>
</table>
</form>

Write query for delete post:

 <!--?php
  if($_POST['delete']){
  //print_r($_POST);
  $checkbox=$_POST['checkbox'];
  //exit;
  for($i=0;$i<count($checkbox);$i++){
  $del_id = $checkbox[$i];
  $sql = "DELETE FROM tbltest WHERE sno='$del_id'";
  $result = mysql_query($sql);
  }
  // if successful redirect to delete_multiple.php
  if($result){
  echo "<meta http-equiv=\"refresh\" content=\"0;URL=checkBoxDelete.php\"-->";
  }
  }
  ?&gt;

Embedding Fonts in Cascading Style Sheets (CSS) for your Web Sites

Fonts are a very effective for Web UI design. Changing font face to desire font-family is not so easy and it make quite excellent interface when you are success. Each font-face is not web safe to embbed for your web. So here are some tips when I think may be useful for you to make a success.
Most of the designer faces this problem when testing their site in various browser using nonstandard fonts, because there’s a good chance your visitors won’t be able to see those fonts in their browsers. The older browsers can display only the fonts installed on user’s systems, making it almost impossible to build creative font choices into your designs.
In the past most deginer used a grphical image for the typical layout instead of font to show the right layout of the font. But that was really a headache when we need to change the font-size, color and other attributes. And another disadvantage was SEO which was totally impossible for search engines to index.
Now go for solution:
Generate or download web safe fonts and upload them in your destination folder and now your style sheet look like:

@font-face {
        font-family: 'YourFontFamily';
        src: url('myfont-webfont.eot?') format('eot'),
             url('myfont-webfont.woff') format('woff'),
             url('myfont-webfont.ttf')  format('truetype'),
             url('myfont-webfont.svg#svgFontName') format('svg');
}

Or use the Open type format:

@font-face {
font-family: 'YourfontFamily';
src: url(Delicious-Roman.eot);
src: local('Delicious'), local(Delicious'),
url(Delicious-Roman.otf) format('opentype');
}

You can create open type font at: http://edward.oconnor.cx/2009/07/how-to-create-eot-files-without-microsoft-weft
Use font in your css:

#div {
       font-family: 'YourFontFamily', Arial, sans-serif;
}

And Finally fontsquirrel.com allows you to upload a font (make sure the license allows this) and will then create the various versions of the font for you.

Object Oriented PHP (Part-1)

Class

Object Oriented PHP revolves around the concept of a grouping function (Called Method) and variables (Called properties into an entity called class.

Features of Object Oriented PHP

  • Class and Object
  • Constructor and Destructor
  • Visibility or data encapsulation
  • Inheritance
  • Constants and Static Methods
  • Interface
  • Abstract Classes

Example

<!--?php
	class calculator
    {
    	function assign(){
        	$this--->a=10;
            $this-&gt;b=5;
           }
         function sum(){
         return $this-&gt;a+$this-&gt;b;
        }
     }
     $c=new calculator();
     $c-&gt;assign();
     echo ("Sum=".$c-&gt;sum());
 ?&gt;

Constructor and Destructor:

Constrator is a special method which is called autometically on object creation.

Destructor is a special method which is called automatically when object is destroyed.

You can see the example below where I have used a simple class foo to show the method of constructin and destruction.

 <!--?php
 class foo{
 	function __construct(){
    	echo __METHOD__."<br/-->";
       }
     function __destruct(){
     	echo __METHOD__;
       }
     }
   $obj=new foo();
 ?&gt;

Real Time Use of Constructor and Destructor Example

Now here I am using the contructor and destructor to connect with database and fetch record.

 <!--?php
 	class dbconn{
	function __construct ($host, $user, $pass, $db)
	{
        $this--->conn=mysql_connect($host, $user, $pass) ;
        mysql_select_db($db);
	}
	function selectAll($query)
	{
	$rs=mysql_query($query) or die(mysql_error());
	$data=array();
	while($row=mysql_fetch_assoc($rs))
		{
		$data[]=$row;
		}
	return $data;
	}
 
	function __destruct()
	{
	mysql_close($this-&gt;conn);
 }
}
$db=new dbconn("localhost", "root", "", "mydb");
$data=$db-&gt;selectAll("SELECT * FROM student");
if(sizeof($data)==0){
	echo "No records found.";
	exit;
	}
?&gt;
<table>
<tbody>
<tr>
<th>Roll</th>
<th>Name</th>
<th>Address</th>
<th>Phone</th>
</tr>
<!--?php
foreach ($data as $student){
?-->
<tr>
<td><!--?php echo $student['roll'];?--></td>
<td><!--?php echo $student['name'];?--></td>
<td><!--?php echo $student['address'];?--></td>
<td><!--?php echo $student['phone'];?--></td>
</tr>
<!--?php
}
?--></tbody>
</table>

5 PHP, Ajax, MySql, Javascript Chain Select

1. DHTML GOODIES (PHP-Ajax)

2. Your Inspiration Web (PHP Ajax)

3. Dynamic Drive (Java Script)

4. Chained Selects jQuery Plugin (jQuery Plugin)

5. Codeassembly

A Simple Javascript Chain Select

 
<script type="text/javascript"><!--mce:0--></script>
 
<select id="first" name="first">
<option value="0">
None  </option>
<option value="1">
Fruit  </option>
<option value="2">
Drink </option>
<option value="3">
Stationary  </option>
</select>
<div id="div1" style="display: none;">
<select id="right" name="second">
<option value="1">
Apple </option>
<option value="2">
Banana  </option>
<option value="3">
Mango  </option>
</select></div>
<div id="div2" style="display: none;">
<select id="right" name="second">
<option value="1">
Coffee </option>
<option value="2">
Tea </option>
<option value="3">
Beer  </option>
</select></div>
<div id="div3" style="display: none;">
<select id="right" name="second">
<option value="1">
Book </option>
<option value="2">
Notebook</option>
<option value="3">
Pen</option>
<option value="4">
Brush</option>
</select></div>

5 Object Oriented PHP Tutorial for Beginners

1. Understanding Objects and Classes

Before you can get too deep into the finer points of OOP, a basic understanding of the differences between objects and classes is necessary. This section will go over the building blocks of classes, their different capabilities, and some of their uses.

 

OOPHPRead More

2. What is OOP

OOP was first invented for the purpose of physical modelling in the Simula-67.
Whilst there is no hard and fast definition of what Object Oriented Programming (OOP) is, we can define. So lets just use this loose definition for now and it is left to reader to make up their own minds about what a decent definition is. Object Oriented Programming (OOP) is a programming concept that treats functions and data as objects. OK, not the best definition but gives us an opening. The key word here is objects. As we progress through this tutorial we will see how data and functions can be represented as re-usable objects, thus cutting down on code and time.

Read More

3.  What the heck are Objects and Classes?

OO PHP

Classes, at their simplest point, are just receptacles of functions. They can be compared to a folder on your computer (assuming you aren’t running DOS). Inside the folder you may have three files, or in this case, functions. Let’s use a classic example, a Dog.

Read More

 

4. Object-Oriented PHP for Absolute Beginners

This tutorial introduces you to object-oriented programming in PHP. You’ll explore the basics of object-oriented programming, and learn how to write simple object-oriented PHP scripts.

Read More

5. What is an Object?

An object is a self-contained piece of functionality that can be easily used, and re-used as the building blocks for a software application.Objects consist of data variables and functions (called methods) that can be accessed and called on the object to perform tasks. These are collectively referred to as members.

 


accountNumber = $acctNumber;
$this->accountname = $acctName;
}

public function __destruct() {
echo ‘Object was just destroyed
‘;
}

public function setAccountNumber($acctNumber)
{
$this->accountNumber = $acctNumber;
}

public function setAccountName($acctName)
{
$this->accountName = $acctName;
}

public function getAccountName()
{
return $this->accountName;
}

public function getAccountNumber()
{
return $this->accountNumber;
}

}
?>

Read More

Illustration Image into Vector Graphics Tutorial

1. Gomediazine

1

2. How to Make an Attractive Vector Butterfly

3. An Urban-Style Piece of Artwork

4. Turn Digital Images into Vector Artwork with PowerTRACE

4

5. Turn a Photo into a Water Color Painting

5

6. Converting an image into vector paths with Illustrator

6

7. Tracing Shapes

8. Vectoring Hair

8

9. Illustration, from sketch to finish

9

10. Tracing Photo

10

11. Watercolor Art Brush

11

12. Create Realistic, Vector Bubbles

12

PHP Array Tutorial

Arrays are special data types. An array is a data structure that stores one or more values in a single value. That means Arrays are variables that store sets of values.

PHP Array Syntax:
array( [key =>] value, …)

Key: key may be an integer or string
Value: A value can be of any PHP type

A simple example without key:

$vehicle=array(“Car”, “Bus”, “Taxi”);

A simple example with key:

$vehicle=array(‘personal’=>”Car”, ‘cheapest’=>”Bus”,’easy’=>”Taxi”);

Printing Array Values:

$vehicle=array(“Car”, “Bus”, “Taxi”);

echo $vehicle[0] ;

Will print Car because Car is the zero index of array.

Looping Through array:

$vehicle=array(“Car”, “Bus”, “Taxi”);

foreach($vehicle as $vehiclename){

echo $vehiclename.”<br>”;

}