Thursday, May 28, 2009

Calling JavaScript Function from hyper link

While working on my project, i was thinking of a way to inform a user to click on a certain link before clicking on a particular. So, Javascript was an option to do that now the question arises

How to execute a java script function by clicking on link?



first thing i do is call the function after the href tag like
<a href="funciton_call();"> but this does not work...
first i was getting syntax error than i don't know what i did i started getting

permission denied

403 error....

then i have to call my might

Google

to rescue me out of this situation...

Google gave me couple of articles related to this issue but there is one article that explain the lots ways of achieving this or why use Javascript in this post i like to summarize article " Links & Javascript living together in harmony" by Jeff Howden.


To ways to open a link in a new window




  • <a href="#" onclick="window.open('somedoc.html', 'newWindow')" >click here</a>
    Howden J. 2002,"Links & JavaScript Living Together in Harmony",sydney,29-05-09,http://www.evolt.org/node/20938

  • calling by pseudo-protocol method

    <a href="JavaScript:window.open('somedoc.html', 'newWindow')">click here</a>
    Howden J. 2002,"Links & JavaScript Living Together in Harmony",sydney,29-05-09,http://www.evolt.org/node/20938



calling by pseudo-protocol method cause a line break if user try to open a web-page in a new window by doing shift+click .

In this article author explains the implication arises from using these methods.he said if you disable java script the first method will cause the browser to jump to the top of document and second method does nothing.

Another way to open a new window for non-Javascript user is?



<a href="somedoc.html" target="newWindow" >click here</a>

and if user want to open a pop up window, he can do this by using onclick event

<a href="somedoc.html" target="newWindow" onclick="window.open(this.href, this.target); return false"
>click here</a>
Howden J. 2002,"Links & JavaScript Living Together in Harmony",sydney,29-05-09,http://www.evolt.org/node/20938


Calling a function from a href tag for javascript compatible browser



<a
href="js_required.html" onmouseover="window.status = 'click here'; return true;"
onmouseout="window.status = '';" onclick="myFunction(); return false;"
>click here</a>

Calling a function from a href tag for non-javascript compatible browser



<a
href="js_required.html"
onmouseover="window.status = 'click here'; return true;" onmouseout="window.status = '';" onclick="return myFunction()">click here</a>
Howden J. 2002,"Links & JavaScript Living Together in Harmony",sydney,29-05-09,http://www.evolt.org/node/20938

Monday, May 18, 2009

Referential integrity constraint in MySQL

Hey guys!
This post is response to article "Using foreign keys and referential integrity in MySQL" at http://www.builderau.com.au/program/mysql/soa/Using-foreign-keys-and-referential-integrity-in-MySQL/0,339028784,339237600,00.htm

Following is a summary of how to use foreign key constraint in MySQL.

Three condition should met in accordance to use foreign key constraint among tables in MySQL:-


  • INNOBD type

    Both table should be of INNOBD type


  • Field my be indexed

    Field used in the foreign key constraint should be indexed.


  • Data type should be similar

    Data types of the field used in the foreign key relationship should be similar.



Syntax for this:-
lets assume we have two tables parent and child.

  • Creating parent table

    create table parent(id int NOT NULL Auto_Increment PRIMARY KEY,f_name varchar(15))ENGINE=INNODB;


  • Createing child table

    create table child(id int NOT NULL,l_name varchar(15))ENGINE=INNODB;

    .

  • adding foreign key constraint

    ALTER TABLE child
    ADD INDEX(id),
    FOREIGN KEY(id) REFERENCES parent(id);


    Note: we can define foreign key constraint while defining table as:

    create table child(id int NOT NULL,l_name varchar(15),INDEX(id),FOREIGN KEY(id) REFERENCES parent(id));



Significance of Foreign key Constraint!


Foreign key constraint help us in achieving Referential Integrity in MySQl. With help to reduce redundancy in database as record can be added to reference(child) table is corresponding field value exist in the refereed(parent) table.


Lets add values in to the table created above
insert into parent values (1,'John'),(2,'Peter'),(3,'William');
Now if this command is executed
insert into child values (4,'walter');
this will give an error as there is no record in parent table with field id value 4.



ON DELETE CASCADE on UPDATE CASCADE

MySQL require above keyword in foreign key constraint if user want to delete corresponding record in child table when a record in parent table is deleted.

syntax for this:

create table child(id int NOT NULL,l_name varchar(15),INDEX(id),FOREIGN KEY(id) REFERENCES parent(id) ON DELETE CASCADE ON UPDATE CASCADE);

Friday, May 15, 2009

Page rank algorithm!

Hey Guys!
this is a part of my assignment for other subject (Unix-system programing) . This article is about page rank algorithm used by goggle to find out relevance of page when the search query is process. i thought i might share it with you all as it describe the process how goggle process search query in simple language.Below is the summary of this article written by Ian Rogers, those who are interested can click on the link at the end of this post to read original article......

Ques1) what is Page Rank?


Ans 1) Page rank can be simply defined as one of the methods used by the Goggle to determine the relevance or importance of web-page and it changes whenever goggle does re-indexing. Page rank does not tell anything about content of size of page, the language or text.
whenever a search query is process by goggle, goggle looks at the url of the page displayed by browser striping off everything down the last "/", if the Toolbar PR of that parent exist goggle subtracts 1 from it and display Toolbar PR of this page. If Toolbar PR of that parent does not exist it jump to parent's parent's page and subtract 2 and so on all the way up to root of the site before displaying PR in Toolbar.


Page rank can also be define as vote of all the other pages on Internet, revealing about the importance of that page it is calculated by following formula.

  • PR(A)=(1-d)+d(PR(T1)/C(T1)+........PR(Tn)/C(Tn)


where:-


  • PR(Tn):- self importance of each page.
  • C(Tn):- vote spread by page to its outgoing links.
  • PR(Tn)/C(Tn)- if the page contains back links from page the share of vote that
    page will get is "PR(Tn)/C(Tn).
  • d - this is multiplying factor
  • 1-d - to keep sum of all pages equal to 1 this multiplying factor is introduced.



Total of 13 example are explained in this article from simple to complex in ascending order.Describing how PR in calculated in various scenario? and how can we increase the PR of the home page?


link:- http://www.ianrogers.net/google-page-rank/

Friday, May 8, 2009

How to give <TAB> in Html

Hey guys!
if you all are struggling with this question of how to give <TAB> in Html
the solution is :-
use <t> element,write your text and end with </t> it easy...

JUST KIDDING! HE. HE.



is given in web page by using non-breaking space &nbsp; character followed by the actual text. for example:

example(not follwed by &nbsp;) will look like

example

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;( will shown as)

       example

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;example ( will displayed as)
                 example

so more &nbsp; more is the spacing of character/word from preceding characters/words


                                                     reference (http://webdesign.about.com/od/intermediatetutorials/qt/tiphtmltab.htm)
http://www.cookwood.com/html/extras/entities.html

Helpful tips for desgining a website


  • Points to be kept in mind while designing web page:-

    • Website should be easy to read.
    • Frames and Table should be avoided because of following reason:-

      • They slow down the uploading of web pages.

      • Web pages with frames and table receive low ranking in search engine and your work may get unnoticed.

      • CSS is much better and flexible way and frames and table are history.



  • Website should be readable.

    Short paragraphs, small text size and contrast between text color and background of web pages.Second thought should be given how web page will look like when the user print them, color choice which look good on screen may not be easy to read when printed out.


  • How the attract visitors to the website.

    • Meta tags.

      As the search engine scans the meta tags for finding searched string, so meta tags must be included in the web pages.

    • Keywords should be used for naming the web pages.

    • Lots of images and tables should be avoided as they made scanning of the web pages harder.




  • Web site address

    There are lots of places on the world wide web where web sites can be hosted for free. Web site name should be easy to understand and spell and its good if it include keywords in it.




                                                                 reference
                                 (http://nzwebs.com/webcoach.htm)


Sunday, April 26, 2009

Effective interaction between php and MySQL

As i know how to make HTML forms,and have moderate knowledge of PHP and MySQL so its time to try out some data sharing between php and MySQL.


  • Establishing a connection
    First of all we have to build a connection between php functions and MySQl and the command to do that is:-
    mysql_connect("Hostname","username","password");

  • Selecting a database
    Once the connection is established an appropriate database is selected and the command for that is:-

    mysql_select_db("database_name",connection_variable);

  • Executing the mysql queries
    mysql_queries is executed by the following command:-

    mysql_query( mysql_query variable, connection variable);



( Meloni , Julie C. 2005," Sams teach yourself PHP,MysQL and Apache all in one", Sams , ed:2.)

Friday, April 24, 2009

Exploring MySQL

Before jumping on to project, i decided to do some data manipulation in MySQL so that i have better understanding of it syntax. This turn out to be good decision as i have work on any Database software for about 6 month, after a long hit and trial i learn to following things about MySQL database:-


  • MySQL Data Types

    • Numeric data types

      • INT
      • TINYINT
      • SMALLINT
      • MEDIUMINT
      • BIGINT
      • FLOAT(M,D)
      • DOUBLE(M,D)
      • DECIMAL(M,D)

        Note: term signed and unsigned can be used in numeric data types

    • Date and Time types

      • DATE
      • DATETIME
      • TIMESTAMP
      • TIME
      • YEAR(M)

    • String Types

      • CHAR(M)
      • VARCHAR (M)
      • BLOB or TEXT
      • TINYBLOB or TINYTEXT
      • MEDIUMBLOB or MEDIUMTEXT
      • LONGBLOB or LONGTEXT
      • ENUM



  • First thing is to create our database which can be done by executing following command:-
    CREATE DATABASE [IF NOT EXISTS] "database name"
    [[default] CHARACTER SET "character set name"]
    [[default] COLLATE "collation name"]

    (Sheldon, Robert and Moes Geoff 2005,"Beginning MySQL",JohnWiley and sons,pg 140).

    or simply:-

    CREATE DATABASE "database name";
    if CHARACTER SET AND COLLATE are not define that MySQL will use the default value.

  • use this command is used to change database.The syntax of this is:-
    mysql> use datbase_name
    .
    Note: this command does not followed by semi colon(;) like other commands


  • For creating table the command is:-
    mysql>CREATE TABLE table_name (column name column type);

    Note: table would be created in the selected database,make sure the right database is selected.
  • For entering data in to table the command is:-

    mysql>INSERT INTO table_name (column list) VALUES (column values);

  • SELECT command is used to retrieve data from the tables.

    mysql>SELECT expressions_and_columns FROM table_name
    [WHERE some_condition_is_true]
    [ORDER BY some_column [ASC | DESC]
    [LIMIT offset, rows]


    ORDERBY by column_name can be used with select to display result in specified sorted order.

  • Selecting from a Multiple Tables can be done with the following command:-
    mysql> (select column list) from (table name) where condition;

  • For UPDATING the records is done by:-

    • mysql> update table_name set Column_name = Value;

    • For conditional Updates the syntax is:-

      mysql> update Table_name set column_name where condition;


  • Replacing a RECORD can be done by:-

    mysql> replace into table_name values ();

  • Deleting a record :-
    mysql> DELETE from table_name [where some_condition_is_true][Limit rows]( Meloni , Julie C. 2005," Sams teach yourself PHP,MysQL and Apache all in one", Sams , ed:2.)

  • Length and concatenation function

    • length(), octet_length().char_length(), and character_length() all calculate number of characters in string. syntax is:-

      mysql> select length ('string';


    • To concatenate two string, MySQL have concat() function,
      To concatenate a string with space the function is concat_ws();

    • Trimming and padding
      rtrim() and ltrim() remove the white spaces from the right and left of the string respectively. rpad() and lpad() adds a string to the right and left of the string respectively.

    • To locate a part of string in another string the MySQL has Locate(), syntax is:-

      mysql> select locate( 'string to be find', ' from this string', position from where to start searching);


    • To extract a substring from a target string, mysql has:-
      Substring(), Left() and Right() functions:-


      mysql> select substring("target string", starting position, end position);

      mysql> select left("target string", till this position from left);

      mysql> select right("target string", till this position from right);

    • String modification functions
      For transforming a string into lower and upper case lcase() and ucase() are available:-
      mysql> select lcase('string' or condition)

      mysql> select ucase('string' or condition)

      MySQL have repeat() for repeating a string number of time and replace() from replacing a occurrence of given string from target string.

      mysql> select repeat(" string", number of time);

      mysql> select replace ( ' given string', ' string to be replace',' string with which to replace');









( Meloni , Julie C. 2005," Sams teach yourself PHP,MysQL and Apache all in one", Sams , ed:2.)
(Sheldon, Robert and Moes Geoff 2005,"Beginning MySQL",JohnWiley and sons).