Thursday, 6 May 2010

JQuery Intro

Hi There,
If you are a web developer i am sure you must hear about JQuery if not it is a complete JavaScript library that can do what every you can think of into a web browser.

I will give you some tips how to work with JQuery so let's go
to work with JQuery do the following
1) include the core library (download the jquery-X.X.X.js) file from http://jquery.com/
2) include the file into you page as
<script src="jquery-1[1].3.2.js" type="text/javascript">
congratulation u now use jquery

so how to use it ?
very simple use jquery operator $(jqueryReference).jqueryFunction();
let's take it step by step,

the first part is $(jqueryReference) what is the jqueryReference ?
it should be one of this 5 notation:

1)no prefix  $('div') — Accesses all the div elements in the HTML(i.e any HTML tag :table,span,div,...)
2)# prefix  (hash prefix) $('#A') — Accesses all the HTML elements with id='A'
3). prefix(dot prefix) $('.b') — Accesses all the HTML elements with class='b'
4)nonElement = $.somefunction();(used as independent function like $.ajax({...}); )
5) a css selector which is a littel bit complex ($("div > div > span").doSomething() which will get all the spans that is inside div and this div is inside another div)
jqueryReferences may add to them something called custom selectors like
$('div : even'),$('div : odd') ,$('div : eq(0)') and  ......
$('div : even').someFunction() that will select only the even div in the document and apply someFunction() to them so if your code is like
<div> 0 </div>
<div> 1 </div>
<div> 2 </div>
<div> 3 </div>
<div> 4 </div>
the select divs is the divs the contains 0,2,4 (the first ,third and fifth).
$('div : odd').someFunction(); will select 1,3
and $('div:eq(1)').Somefunction() will select only the div that contain 1 (the second div)
(note: jquery count from 0)

now we finish the first part let's go to the second part which is the functions
$('jqueryReference').function();
the function is can be categorized into 2 category and they are:
1)on what they applied to ?
2)where they come from ?

let begin on the functions
1) on what they applied to ?
the functions is applied on 1 of 2 things html element or document
so when we use $('div') or $('#id') or $('.class') we apply the function to those element's only like( $('#id').show() )
but when we use $.function() we will use a function which not related to a spacial html element (like $.ajax({...}) )

2)where they come from ?
the come from 2 main source the engine or plugin
- the engine is jquery-X.X.X.js which contain the most important function (i.e. ajax....) and u can use them once u include the core libaray
- the plugin is any library the depend on jquery like fancyBox which u can call once u call their library (don't worry most of them are well documented ,tested and have how to use)

finally if u need any thing about JQuery don't worry just call me on the mobile. hahaha i am kidding google it and u will found million of solution.
nothing more to say so have a good day with jquery ;)
More reference =====> http://www.jquery.com
GOOD BYE

Tuesday, 4 May 2010

MYSQL Data Base Encoding

Hi there,
Today i will talk about how to deal with Multiple language Data base.
first i will talk how to build it from scratch and second how to modify a working copy of database
NOTES:
- in my case i worked with Arabic encoding so i used utf_general_ci as encoding category BUT if the language isn't supported in utf_general_ci choose the supported collection.
- the default encoding for database latin1_swedish_ci.
- My tools => phpMyAdmin , notepad++

Build From Scratch
1) When creating the DB specify the collection to utf_general_ci.
2) When creating the table specify the collection to utf_general_ci.
3) Now each field in the table you need to make it in Arabic make it's collection utf_general_ci.
4) Finally in application to config the Arabic to work fine use this to you connection string :
-General case:
jdbc:mysql://yourhost/yourDB?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8

second: modify a working copy to work with arabic
in my case the database accept Arabic letters and the encoding was latin so i did the following

1) Dump the Database (with phpMyAdmin)
2) Create .txt file
3) copy the dump and paste into the .txt file AND DON'T SAVE THE FILE
4) change the file encoding ( i used the notepad++ encoding tab encode in UTF-8) and save the file
5) you will find the Arabic letter appered :)
6) change the encoding of the DB & tables & fields as the first section.
7) Empty the table and then copy the insert statement from your dump in the .txt file and paste in the phpMyAdmin insert tab


Done :)