OUR MUST POPULAR POST

Wednesday, March 27, 2013

PHP/MySQL Tutorial


Introduction to Database :

Goal of this tutorial

  1. Not to teach everything about PHP,
  2. but provide the basic knowledge
  3. Explain code of examplesProvide some useful references

    What is PHP?

    • PHP == Hypertext Preprocessor
    • Open-source, server-side scripting language
    • Used to generate dynamic web-pages
    • PHP scripts reside between reserved PHP tags
    • This allows the programmer to embed PHP scripts within HTML pages
     

 What is PHP (cont’d)

  • Interpreted language, scripts are parsed at run-time rather than compiled beforehand
  • Executed on the server-side
  • Source-code not visible by client
  • View Source in browsers does not display the PHP code
  • Various built-in functions allow for fast development
  • Compatible with many popular databases 
  • What does PHP code look like?
    • Structurally similar to C/C++
    • Supports procedural and object-oriented paradigm (to some degree)
    • All PHP statements end with a semi-colon
    • Each PHP script must be enclosed in the reserved PHP tag
    •  
    •  
    • <?php

        
      ?>

      Comments in PHP

      •         Standard C, C++, and shell comment symbols
      •  
      •     // C++ and Java-style comment
             # Shell-style comments
             /* C-style comments
             These can span multiple lines */


         
       
       

 

Wednesday, March 13, 2013

jPanelMenu: Slick Navigation-Sidebar With CSS Animations And jQuery


jPanelMenu: Perfect For Responsive Designs

Anthony Colangelo earns his money as a developer for design agency Happy Cog, which with three offices around the USA doesn’t belong to the smaller representatives of the business. In his spare time he likes to fiddle around with JavaScript, pushing out little tools and helpers, most of which he gives away free of charge via his Github profile.
His latest achievement is the jQuery plugin jPanelMenu, which looks as familiar as it is to every digital nomad out there. jPanelMenu delivers a sidebar navigation resembling that of the apps for Facebook and Google + as closely as you can imagine. What distinguishes it from the native app counterparts is its use of web technologies. As such it is the perfect choice for your next responsive web app.
Colangelo wanted it to perfect, thus even implementing the sliding animation the native apps incorporate. He did that by the use of CSS transitions with a fallback to jQuery animations in older browsers. In itself perfectly suited for responsive designs Colangelo recommends to combine it with the jQuery plugin jRespond and delivers an example as to how to do this. jRespond is especially useful to have jPanelMenu turned on or off depending on the break points reached.
Basic Configuration Of A jPanelMenu
Writing jPanelMenu Colangelo thought about users surfing the web without JavaScript and cared not to break the experience for them. Users without Javascript enabled will fallback to a css-styled menu you will have to design specifically. This is easy as jPanelMenu styles do not get in your way. Only while jPanelMenu gets loaded and activated the class .jPanelMenu will be added to the HTML element.
This way you know how to react with CSS. All jPanelMenu-specific styles will be descendants of .jPanelMenu, thus only showing their magic when the class exists. Colangelo shows you how to do this, too.
The whole project is thoroughly and comprehensibly documented and elegantly presented. jPanelMenu is up to the mark of today’s development standards. You should definitely give it a try.

You can take a look at the working demo if you click on the image below:


We will create four steps in our form:
1. username and password fields
2. first and last name and email address
3. age, gender and country
4. summary

First thing to do is to create the html structure. We need a box container with four divs, one for each step. The basic HTML code is the following:
1
2     
3  
4         
5         
6         
7         
8  
9     
10
Inside each box container we will put the fields and a simple helpfull label. You can see the code inside the first box in the code below:
1
2
3     

SIGN UP FOR A FREE WEBEXP18 ACCOUNT

4  
5     
6         
7         At least 4 characters. Uppercase letters, lowercase letters and numbers only.
8  
9         
10         At least 4 characters. Use a mix of upper and lowercase for a strong password.
11  
12         
13         If your passwords aren’t equal, you won’t be able to continue with signup.
14     
      
15     
16
      
We have used three input fields: username, password and confirm password and at the end of the box, an input submit for the next step. The other boxes work in the same way.

At the end of the container box you can see a simple progress bar. This is the necessary code:
1
2     
3     
0% Complete
4
The complete HTML code is the following:
1
2     
3  
4         
5         
6             

SIGN UP FOR A FREE WEBEXP18 ACCOUNT

7  
8             
9                 
10                 At least 4 characters. Uppercase letters, lowercase letters and numbers only.
11  
12                 
13                 At least 4 characters. Use a mix of upper and lowercase for a strong password.
14  
15                 
16                 If your passwords aren’t equal, you won’t be able to continue with signup.
17             
      
18             
19         
      
20  
21         
22         
23             

SIGN UP FOR A FREE WEBEXP18 ACCOUNT

24  
25             
26                 
27                 Your First Name.
28                 
29                 Your Last Name.
30                 
31                 Your email address. We send important administration notices to this address
32             
      
33             
34         
      
35  
36         
37         
38             

SIGN UP FOR A FREE WEBEXP18 ACCOUNT

39  
40             
41                 
42                      0 - 17
43                     18 - 25
44                     26 - 40
45                     40+
46                 
47                 Your age range.  
48  
49                 
50                     Male
51                     Female
52                 
53                 Your Gender.  
54  
55                 
56                     United States
57                     United Kingdom
58                     Canada
59                     Serbia
60                     Italy
61                 
62                 Your country.  
63  
64             
      
65             
66  
67         
      
68  
69         
70         
71             

SIGN UP FOR A FREE WEBEXP18 ACCOUNT

72  
73             
74                 

Summary

75  
76                 
77                     
Username
78                     
Password
79                     
Email
80                     
Name
81                     
Age
82                     
Gender
83                     
Country
84                 
85             
      
86             
87         
88  
89     
90
91
92         
93         
0% Complete
94
As you can see, in the fourth step the table is empty. We fill it with the information entered by the users using jQuery.

Now we need to add the style on the form. First, we use the @fontface rule for using a custom font. I’ve used the Cantarell font. The complete CSS Code is listed below:
1 /* CSS Reset (Eric Meyer) */
2 html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent;margin:0;padding:0}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}:focus{outline:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0}
3  
4 @font-face {
5    font-family: 'Cantarell';
6    src: url(../fonts/Cantarell-Regular.eot);
7    src: local('Cantarell'), url('../fonts/Cantarell-Regular.ttf')format('truetype');
8 }
9  
10 body {
11     background-color: #f9f9f9;
12     color: #222;
13     font-family: Cantarell, Verdana, sans-serif;
14     font-size: 12px;
15 }
16  
17 input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner { border : none; }
18 input[type="submit"]:focus, input[type="button"]:focus { outline : none; }
19  
20 .clear { clear: both; }
21  
22 #container {
23     background: url('../images/container.png') no-repeat;
24     width: 754px;
25     height: 370px;
26     margin: 20px auto;
27     padding: 50px 0;
28     overflow: hidden;
29     position: relative;
30 }
31     #container #first_step, #second_step, #third_step, #fourth_step { display:none; }
32     #container #first_step { display: block; }
33  
34     #container .form { margin: 66px 72px 0 72px; }
35  
36     #container h1, #container h2 {
37         font-size: Cantarell, Verdana, sans-serif;
38         text-align: center;
39         font-size: 24px;
40         text-shadow: 1px 1px 2px #222;
41     }
42         #container h1 span { color: #a90329; }
43  
44     #container h2 {
45         color: #888;
46         font-size: 20px;
47         text-align: left;
48         text-shadow: none;
49     }
50  
51     #container table {
52         margin: 20px 40px;
53         font-size: 14px;
54         font-weight: bold;
55     }
56         #container table td {
57             padding: 5px 10px;
58         }
59             #container table td:nth-child(2) {
60                 color: #a90329;
61             }
62  
63     #container input, #container select {
64         background: url('../images/input.png') no-repeat;
65         color: #888;
66         border: 1px solid #ccc;
67         font-family: Cantarell, Verdana, sans-serif;
68         font-weight: bold;
69         font-size: 15px;
70         width: 300px;
71         height: 35px;
72         padding: 0 25px;
73         margin: 20px 0;
74         float: left;
75  
76         border-radius: 6px;
77         -moz-border-radius: 6px;
78         -webkit-border-radius: 6px;
79     }
80         #container input.submit {
81             background: url('../images/button.png') no-repeat;
82             border: none;
83             cursor: pointer;
84             width: 85px;
85             height: 38px;
86             position: relative;
87             bottom: 2px;
88             left: 655px;
89         }
90             #container input.submit:focus { border: none; }
91  
92         #container input.send{ background: url('../images/send.png') no-repeat; }
93  
94         #container input.error { border: 1px solid red; }
95         #container input.valid { border: 1px solid #1FFF00; }
96  
97         #container input:focus, #container select:focus {
98             border: 1px solid #a90329;
99             color: #a90329;
100         }
101  
102     #container select { padding: 5px 0 5px 25px; }
103         #container option { padding: 0 15px; }
104  
105     #container label {
106         color: #666;
107         font-size: 12px;
108         font-weight: bold;
109         line-height: 14px;
110         float: right;
111         margin: 23px -25px;
112         width: 270px;
113     }
114  
115 #progress_bar {
116     background: url('../images/progress_bar.png') no-repeat;
117     width: 339px;
118     height: 24px;
119     margin: 0 auto;
120     position: relative;
121 }
122  
123 #progress {
124     background: url('../images/progress.png') repeat-x;
125     width: 0px;
126     height: 23px;
127  
128     border-radius: 20px;
129     -webkit-border-radius: 20px;
130     -moz-border-radius: 20px;
131 }
132 #progress_text {
133     position: relative;
134     line-height: 21px;
135     text-align: center;
136     font-weight: bold;
137     color: white;
138     text-shadow: 1px 1px 2px #222;
139     width: 339px;
140     height: 24px;
141     top: -23px;
142     left: 0;
143 }


We’re going to use jQuery for:
- slide the steps
- check if the data are valid
- change the completion percentage of progress bar

We need load jQuery library inside the page and then to use two plugins:
- jQuery UI, the most famous plugin used to extend the jQuery functionality.
- jQuery inputfocus, my jQuery plugin used to manage focus and blur events of the form.
Our jQuery code is listed below:
1 $(function(){
2     //original field values
3     var field_values = {
4             //id        :  value
5             'username'  : 'username',
6             'password'  : 'password',
7             'cpassword' : 'password',
8             'firstname'  : 'first name',
9             'lastname'  : 'last name',
10             'email'  : 'email address'
11     };
12  
13     //inputfocus
14     $('input#username').inputfocus({ value: field_values['username'] });
15     $('input#password').inputfocus({ value: field_values['password'] });
16     $('input#cpassword').inputfocus({ value: field_values['cpassword'] });
17     $('input#lastname').inputfocus({ value: field_values['lastname'] });
18     $('input#firstname').inputfocus({ value: field_values['firstname'] });
19     $('input#email').inputfocus({ value: field_values['email'] });
20  
21     //reset progress bar
22     $('#progress').css('width','0');
23     $('#progress_text').html('0% Complete');
24  
25     //first_step
26     $('form').submit(function(){ return false; });
27     $('#submit_first').click(function(){
28         //remove classes
29         $('#first_step input').removeClass('error').removeClass('valid');
30  
31         //ckeck if inputs aren't empty
32         var fields = $('#first_step input[type=text], #first_step input[type=password]');
33         var error = 0;
34         fields.each(function(){
35             var value = $(this).val();
36             if( value.length
37                 $(this).addClass('error');
38                 $(this).effect("shake", { times:3 }, 50);
39  
40                 error++;
41             } else {
42                 $(this).addClass('valid');
43             }
44         });
45  
46         if(!error) {
47             if( $('#password').val() != $('#cpassword').val() ) {
48                     $('#first_step input[type=password]').each(function(){
49                         $(this).removeClass('valid').addClass('error');
50                         $(this).effect("shake", { times:3 }, 50);
51                     });
52  
53                     return false;
54             } else {
55                 //update progress bar
56                 $('#progress_text').html('33% Complete');
57                 $('#progress').css('width','113px');
58  
59                 //slide steps
60                 $('#first_step').slideUp();
61                 $('#second_step').slideDown();
62             }
63         } else return false;
64     });
65  
66     $('#submit_second').click(function(){
67         //remove classes
68         $('#second_step input').removeClass('error').removeClass('valid');
69  
70         var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
71         var fields = $('#second_step input[type=text]');
72         var error = 0;
73         fields.each(function(){
74             var value = $(this).val();
75             if( value.length
76                 $(this).addClass('error');
77                 $(this).effect("shake", { times:3 }, 50);
78  
79                 error++;
80             } else {
81                 $(this).addClass('valid');
82             }
83         });
84  
85         if(!error) {
86                 //update progress bar
87                 $('#progress_text').html('66% Complete');
88                 $('#progress').css('width','226px');
89  
90                 //slide steps
91                 $('#second_step').slideUp();
92                 $('#third_step').slideDown();
93         } else return false;
94  
95     });
96  
97     $('#submit_third').click(function(){
98         //update progress bar
99         $('#progress_text').html('100% Complete');
100         $('#progress').css('width','339px');
101  
102         //prepare the fourth step
103         var fields = new Array(
104             $('#username').val(),
105             $('#password').val(),
106             $('#email').val(),
107             $('#firstname').val() + ' ' + $('#lastname').val(),
108             $('#age').val(),
109             $('#gender').val(),
110             $('#country').val()
111         );
112         var tr = $('#fourth_step tr');
113         tr.each(function(){
114             //alert( fields[$(this).index()] )
115             $(this).children('td:nth-child(2)').html(fields[$(this).index()]);
116         });
117  
118         //slide steps
119         $('#third_step').slideUp();
120         $('#fourth_step').slideDown();
121     });
122  
123     $('#submit_fourth').click(function(){
124         //send information to server
125         alert('Data sent');
126     });
127  
128 });
The code from row 3 to 20 activate the inputfocus plugin to each input field. The code from row 27 to 64 check the validity of the data entered by the user (if username and password length is greather than 4 characters, if the password and confirm password fields are equal), then update the progress bar value and then slide to second step.
The code from row 71 to 100 check the data integrity for the second step (if first and last name aren’t empty and if the email address is valid). The rest is similar to the previous code.


We have seen how simple its to create a multistep signup form. This is only an example so I omitted some features as back button, and more others. Anyway the example is ready to use and it needs only to change the form action with the link of your php file used to store data and to edit the jQuery line 125 to: $(‘form’).unbind(‘submit’).submit();. You can also decide to use an AJAX calls to send the informations to server, and again it’s very easy to implement.
To see form in action click on the image below:

Makisu – Sushi-Inspired CSS 3D Navigation for jQuery


Makisu – the virtual bamboo mat

Justin Windle aka soulwire, born in the UK, but now living in the United States, developed Makisu, a concept resembling the older Paperfold CSS, but going much farther than that. It is actually easily implementable in live websites through its iteration as a jQuery plugin. The strange name stems from the Japanese language, where a Makisu is a bamboo mat used to produce a certain kind of sushi or just to squeeze moisture out of fruits and other overly moist nourishments.

Makisu fully rolled out
Justin Windle’s Makisu can not be used to produce sushi obviously, neither can you squeeze fruit-juices with it. Anyway, take a look at it and you’ll immediately understand the name. The Makisu navigation menus unfold like a bamboo mat let loose while held on one side. The navigation items roll out and the virtual bamboo mat even swings back and fourth, making for a realistic effect. The dropdowns are made up of list items, one per line. These items can be toggled to show or stay invisible. Unfolding the dropdown leads to the bamboo effect.
Makisu is a mere CSS concept using CSS 3D transforms. As such it only works in some of the most recent versions of browsers, as they are Chrome, Firefox, Safari, and the standard browsers in Android, iOS and Blackberry. Internet Explorer 10 should also be displaying Makisu correctly. As I am testing some of the most recent Ultrabooks at the moment I took one and fired up IE 10 to double-check if something that beautiful but at the same time demanding would really, I mean really as in real not really as on a spec paper, work in a Microsoft environment. I did not get disappointment, given that I expected it not to. Makisu actually works, but the whole experience is sluggish, slow and all the animation effects are left out. No elegantly swinging at the end of the process. Microsoft proves to be reliable…

Makisu in full motion
Makisu as a CSS concept would not be very easy to implement into your own website. That’s why Justin wrapped a jQuery plugin around it. This makes implementation a snap. Simply call jQuery and the plugin in the head of your document and call the function like this:
1
2
3
4
5
$( '.list' ).makisu({
    selector: 'li',
    overlap: 0.2,
    speed: 0.8
});
The most important parameter is the choice of selectors. In the above shown example it is the regularly used li-element, but you could as well go more exotic and choose elements as to your liking. The other options refer to speed and overlapping. 3D effects are provided by the use of perspective and vertex shading via shading.
Makisu can be downloaded and used free of charge from Github. It is only a few days old and – let me say it again – is a concept. If you are the adventurous kind you could of course put it on one of your live websites. Chances are your customers might complain. But boy, it really looks fancy…

Tuesday, March 12, 2013

Typographic Design


Lesson overview

In this lesson, you’ll learn how to do the following:
• Use guides to position text in a composition.
• Make a clipping mask from type.
• Merge type with other layers.
• Use layer styles with text.
• Preview typefaces interactively to choose them for a composition.
• Control type and positioning using advanced type palette features.
• Warp a layer around a 3D object.
This lesson will take about an hour to complete. If needed, download the Lesson08.zip file and extract it. As you work on this lesson, you’ll preserve the start files.

About type

Type in Photoshop consists of mathematically defined shapes that describe the letters, numbers, and symbols of a typeface. Many typefaces are available in more than one format, the most common formats being Type 1 or PostScript fonts, TrueType, and OpenType (see page 266).
When you add type to an image in Photoshop, the characters are composed of pixels and have the same resolution as the image file—zooming in on characters shows jagged edges. However, Photoshop preserves the vector-based type outlines and uses them when you scale or resize type, save a PDF or EPS file, or print the image to a PostScript printer. As a result, you can produce type with crisp, resolution-independent edges, apply effects and styles to type, and transform its shape and size.


Getting started
In this lesson, you’ll work on the layout for the label of a bottle of olive oil. You will start from an illustration of a bottle, created in Adobe Illustrator, and then add and stylize type in Photoshop, including wrapping the text to conform to the 3D shape. You will start with a blank label on a layer above the bottle background.
You’ll start the lesson by viewing an image of the final composition.
1 Start Photoshop and then immediately hold down Ctrl+Alt+Shift (Windows) or Command+Option+Shift (Mac OS) to restore the default preferences.
2 When prompted, click Yes to confirm that you want to reset preferences, and Close to close the Welcome Screen.
3 Click the Go To Bridge button () in the tool options bar to open Adobe Bridge.
4 In the Favorites panel on the left side of Bridge, click the Lessons favorite, and then double-click the Lesson08 folder in the Content panel.
5 Select the 08End.psd file so that it appears in the center Content panel. Enlarge the panel if necessary to get a good close-up view by dragging the right splitter bar to the right.


This layered composite represents a comp of packaging for a new brand of olive oil. For this lesson, you are a designer creating the comp for the product. The bottle shape was created by another designer in Adobe Illustrator. Your job is to apply the type treatment in Photoshop in preparation to present it to a client for review. All of the type controls you need are available in Photoshop, and you don’t have to switch to another application to complete the project.
7 Select the 08Start.psd file and double-click it to open it in Photoshop.
8 Choose File > Save As, rename the file 08Working.psd, and click Save.


Creating a clipping mask from type

A clipping mask is an object or a group of objects whose shape masks other artwork so that only areas that lie within the shape of the masking object are visible. In effect, you are clipping the artwork to conform to the shape of the object (or mask). In Photoshop, you can create a clipping mask from shapes or letters. In this exercise, you will use letters as a clipping mask to allow an image in another layer to show through the letters.

Adding guides to position type

The 08Working.psd file contains a background layer, which is the bottle, and a Blank Label layer, which will be the foundation for your typography. The Blank Label is the active layer on which you will begin your work. You’ll start by zooming in on your work area and using ruler guides to help position your type.
1 Select the Zoom tool () and drag over the black-and-white portion of the blank label to zoom in to the area and center it in the image window. Repeat until you have a nice close-up view of the area, and enlarge the image window if necessary.


2 Choose View > Rulers to turn on guide rulers along the left and top borders of the image window. Then, drag a vertical guide from the left ruler to the center of the label (3½ inches) and release.

Adding point type


Now you’re ready to actually add type to the composition. Photoshop lets you create horizontal or vertical type anywhere in an image. You can enter point type (a single letter, word, or line) or paragraph type. You will do both in this lesson, starting with point type.
1 Make sure that the Blank Layer is selected in the Layers palette. Then, select the Horizontal Type tool (), and in the tool options bar, do the following:
• Choose a sans serif typeface, such as Myriad Pro, from the Font Family pop-up menu, and choose Bold from the Font Style pop-up menu.
• Type 79 pt into the Size field and press Enter or Return.
• Click the Center text alignment button.

2 Click on the center guide in the white area of the label to set an insertion point, and type OLIO in all caps. Then click the Commit Any Current Edits button () in the tool options bar.


The word “Olio” is added to your label, and it appears in the Layers palette as a new type layer, OLIO. You can edit and manage the type layer as you would any other layer. You can add or change the text, change the orientation of the type, apply anti-aliasing, apply layer styles and transformations, and create masks. You can move, restack, copy, and edit layer options of a type layer as you would for any other layer.
3 Press Ctrl (Windows) or Command (Mac OS), and drag the OLIO type to visually center it vertically in the white box.
4 Choose File > Save to save your work so far.