Become Our Fan on Social Sites!

Facebook Twitter

Google+ RSS YouTube

Tuesday 25 March 2014

PHP Database Connection With MySQL

Hello friends, this article is for php beginners who want to know how to connect to MySQL database using PHP code.

Here is your answer, I am explaining you step by step tutorial of how to make connection to MySQL database in PHP (Hypertext Preprocessor) language.

PHP Database Connectivity With MySQL
MySQL - PHP Database Connectivity

Monday 24 March 2014

Cricket Live Scores ~ Live Cricket Score Board

Are you looking for cricket live scores? Following are list of live cricket score update websites.
Cricket Sites In India, Cricket Websites List, Live Score Board, Cricket Live News
Live Cricket Update Score
Live Cricket Score Update Website List

Saturday 22 March 2014

How To Create Message Box In .Net

Message Box is used to inform something to the user. Message box interrupts user and user must have to answer message box to process further. Most of time this type of message box you find in error message, warning message, etc.

In this tutorial, I am explaining about C#.Net message box.

To create message box in C#.Net, you have to include 'System.Windows.Forms' namespace.


How To Create C#.Net Message Box - Dialog Box
C#.Net Message Box

Example:

using System.Windows.Forms;

The name of class used to create message box is 'MessageBox' and contains static method named 'Show()'.

Static method does not need to call using object, it is called directly using class name.

Message box sometimes called dialog box or popup box.

Following are the examples of message box and it is written in Form1_Load event of window form.

1. Simple Message Box

MessageBox.Show("Simple Message Box");

This message box contains just message and no title text displayed.

Simple message box looks like:


Simple Message Box In C sharp dot net







 2. Message Box With Message and Title Text

MessageBox.Show("All Code Tips ~ Programming Blog", "Title: All Code Tips");

This message box contains text message and title text.

This message box looks like:

Message Box With Title Text ~ C sharp dot net







3. Message Box With Different Buttons

DialogResult res = MessageBox.Show("Click on button", "All Code Tips", MessageBoxButtons.YesNo);

This message box contains text message, title text, Yes and No buttons.

This message box looks like:


Message Box With Buttons ~ C sharp Dot Net







MessageBoxButtons enumeration contains following options:
  • MessageBoxButtons.AbortRetryIgnore
  • MessageBoxButtons.OK
  • MessageBoxButtons.OKCancel
  • MessageBoxButtons.RetryCancel
  • MessageBoxButtons.YesNo
  • MessageBoxButtons.YesNoCancel
If you want to get result of what button user clicked then you have to use following code:

DialogResult res = MessageBox.Show("Click on button", "All Code Tips", MessageBoxButtons.YesNo);
if(res == DialogResult.Yes)
{
   MessageBox.Show("You click on Yes button");
}
else
{
   MessageBox.Show("You click on No button");
}


4. Message Box With Icons

DialogResult res = MessageBox.Show("Click on button", "All Code Tips", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

Using MessageBoxIcon enumeration, you can change icon of message box.

This message box looks like:

Message Box with Icons ~ C Sharp Dot Net ~ dialog box with icon








MessageBoxIcon enumeration contains following options:
  • MessageBoxIcon.Asterisk
  • MessageBoxIcon.Error
  • MessageBoxIcon.Exclamation
  • MessageBoxIcon.Hand
  • MessageBoxIcon.Information
  • MessageBoxIcon.None
  • MessageBoxIcon.Question
  • MessageBoxIcon.Stop
  • MessageBoxIcon.Warning
As your requirement, you can use any above options with your message box.

5. Default Button Settings

DialogResult res = MessageBox.Show("Click on button", "All Code Tips", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);

Using MessageBoxDefaultButton enumeration, you can set default button. If you set default Button2 then button - 2 is selected.

This message box looks like:

Dialog Box - Message Box with default button settings ~ C sharp Dot Net








MessageBoxDefaultButton enumeration cotains following options:
  • MessageBoxDefaultButton.Button1
  • MessageBoxDefaultButton.Button2
  • MessageBoxDefaultButton.Button3

6. Setting Message Box Options

DialogResult res = MessageBox.Show("Click on button", "All Code Tips", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2, MessageBoxOptions.RightAlign);

Using MessageBoxOptions enumeration, you can set following options:
  • MessageBoxOptions.DefaultDesktopOnly
  • MessageBoxOptions.RightAlign
  • MessageBoxOptions.RtlReading
  • MessageBoxOptions.ServiceNotification
In above code, we use RightAlign option and that message box looks like:

Message Box - Dialog Box with other options ~ C sharp Dot Net









If you find any problem then comment below.

Wednesday 19 March 2014

JavaScript Dialog Boxes

Here is a tutorial post of dialog boxes / popup boxes in JavaScript. In JavaScript, there are three dialog / popup boxes. These three different types of boxes listed below:
  • Alert Dialog Box
  • Confirm Dialog Box
  • Prompt Dialog Box
JavaScript Popup Boxes
JavaScript Dialog Boxes
Now we will see these three dialog boxes one by one:

1. Alert Dialog Box

Alert dialog box is used to give any message to the user.

Mostly alert dialog box is used in form validation error message display, for example in form, you have email id field and you have not entered email id then as an error message, you can alert user using Alert dialog box.

Example

<head>
   <script type="text/javascript">
      alert('This is Alert Box');
   </script>
</head>

Alert dialog box also can be written using window prefix like below:

window.alert('This is Alert Box');

But you can also write without window prefix.

Alert dialog box contains only one 'Ok' button. User must have to click on 'Ok' button to precess further.

The Alert dialog box looks like as following image:

Alert Dialog Box







 2. Confirm Dialog Box

Confirm dialog box is a dialog box that contains 'Ok' and 'Cancel' button.

Confirm dialog box often used for to accept something from user.

If user clicks on 'Ok' button then confirm dialog box returns true. If user clicks on 'Cancel' button then confirm dialog box returns false.

Example:

<head>
   <script type="text/javascript">
    var result = confirm('Click on button');
    if(result == true)
    {
     alert('Ok button clicked');
    }
    else
    {
     alert('Cancel button clicked');
    }
   </script>
</head>

The confirm dialog box looks like as following image:

Confirm Dialog Box







3. Prompt Dialog Box

Prompt dialog box is used to get user input.

Prompt dialog box can be displayed using prompt() method of window object.

Prompt method takes two parameters: 1) Label of prompt box and 2) Default value for user input field.

Prompt dialog box contains two buttons named 'Ok' and 'Cancel' and one text input field.

If user clicks on 'Ok' button then inputed text is returned and if user clicks on 'Cancel' button then null is returned.

<head>
   <script type="text/javascript">
     var name = prompt('Enter Name : ', 'John Smith');
     alert('Inputed Value : ' + name);
   </script>
</head>

The prompt dialog box looks like as following image:

Prompt dialog box

Tuesday 18 March 2014

Types of CSS

Hello friends, here is a tutorial of types of CSS. CSS stands for Cascading Style Sheet. CSS is used in web development for to style webpage. Using CSS, you can change font-size, font-family, text color, background color, etc.

Cascading Style Sheet Types - CSS
Types of Cascading Style Sheet

There are 3 (three) types of Cascading Style Sheet. There are few advantages and disadvantages of these different types of style sheets.

Following are the list of different types of style sheets:
  • Inline Style Sheet
  • Internal Style Sheet
  • External Style Sheet
Let's understand each style sheet with example codes:

1. Inline Style Sheet

Inline style sheet is embedded to individual elements of HTML.

To give inline style sheet to particular HTML element then use 'style' attribute of any HTML element.

If you give same style to another HTML element, then style code is repeated. It is better to not write too much inline style sheet.

Inline style sheet is useful when you want to override a style sheet.

Example:

<div style="background-color:black;color:white;">
    This is div tag
</div>

OUTPUT:

This is div tag


2. Internal Style Sheet

Internal style sheet is also known as embedded style sheet.

This internal style sheet is written inside <head> tag of HTML.

To write internal style sheet inside <head> tag, you have to use <style> tag of HTML.

Syntax:

<style type="text/css">
   ...
</style>

Scope of this style sheet is within the page. If you want to use this style sheet in another page then you have to write again this internal style sheet in that page.

Example:

<html>
<head>
   <style type="text/css">
     div
     {
       background-color:yellow;
       color:red;
     }
   </style>
</head>
<body>
   <div>
     This is div tag
   </div>
</body>
</html>

OUTPUT:

This is div tag


3. External Style Sheet

This type of style sheet is written in separate '.css' file and linked to the webpage.

This type of style sheet reduces redundant code of style sheet.

Because of separate external '.css' file, you can link it into any number of pages, in short reuse the style.

I highly recommended, to use external style sheet.

There is nothing new to external style sheet creation, just create separate '.css' file like below:

Example:

mystyle.css
div
{
    background-color:cyan;
    color:blue;
}

After creating 'mystyle.css' file then create HTML file named 'mypage.html' and embed this external style sheet file using HTML <link> tag as illustrated below:

mypage.html
<html>
  <head>
    <link href="mystyle.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <div>This is div tag</div>
  </body>
</html>

OUTPUT:

This is div tag

NOTE: These two files 'mystyle.css' and 'mypage.html' must be in same directory/folder.

Sunday 16 March 2014

HTML Image Tag Example

Hello friends, this tutorial is about HTML <img> (image) tag. To display/show image in the webpage then we have to use <img> tag of HTML. Here you can find all required attributes of <img> tag and some tips for image optimization.

HTML img tag
HTML Image Tag Example

Syntax:

<img src="" alt="" />

"src" and "alt" attributes are important in image tag.

There are following important attributes list of image tag:
  • src
  • alt
  • height
  • width
To Read Form Tag. Click Here

To Read Table Tag. Click Here

src attribute:

Src stands for Source and contains value of image path.

For example, if your webpage is saved in some "xyz" directory/folder and image is also in same folder then you have to write following code to display image. Here "allcodetips.jpg" is a image file name, your image file name can be different.

Example:

<img src="allcodetips.jpg" />

If your webpage is saved in "xyz/" directory and image is stored in "xyz/img/" directory then you have to use following code:

Example:

<img src="img/allcodetips.jpg" />


alt attribute:

Alt attribute is second most useful attribute. Alt attribute contains text message and this text message is displayed when image is not display. In short when image is not possible to display at that time alt attribute's value is displayed.

Second use of alt attribute is SEO (Search Engine Optimization) because Search Engine crawler does not crawl images, so crawler crawls src and alt attributes' value.

So always use alt attribute for better Search Engine Optimization.

Example:

<img src="allcodetips.jpg" alt="All Code Tips" />


height attribute:

Height attribute specifies height of image. You can provide height value like 100, 250, 500, etc as your requirement.

Example:

<img src="allcodetips.jpg" alt="All Code Tips" height="250px" />


width attribute:

Width attribute specifies width of image. You can provide percent value to the width attribute like width="100%". You can also provide pixel value to the width attribute.

Example:

<img src="allcodetips.jpg" alt="All Code Tips" width="250px" />


Conclusion:

HTML image tag contains many other attributes, but above listed attributes are most common. You can use events in image tag using onmouseover, onclick, onmouseout, etc.

If you find any difficulty then comment below.

Saturday 15 March 2014

CodeIgniter Table Class Example

We can create table using HTML table tag. But in CodeIgniter, there is a Table Class to create table. It is not mandatory to use this Table Class, we can use simple HTML table tag also.

CodeIgniter Table Class Example
CodeIgniter Table Class Example

This Table Class provides facility of creating table from arrays or database query result set.

1. How To Initialize Table Class?


To initialize Table Class, we have to write following statement in the controller class:

$this->load->library('table');

Now, we can access Table Class library object using $this->table.

2. Create Table From Array

We can create table using multi-dimensional array. First array index becomes table heading. We can also make table heading using set_heading() method.

Example:

$this->load->library('table');
$rows = array(
    array('RollNo','Name','City'),
    array('1','Jignesh','Rajkot'),
    array('2','John','Washington'),
    array('3','Mark','Canada')
);
echo $this->table->generate($rows);


OUTPUT:

RollNoNameCity
1JigneshRajkot
2JohnWashington
3MarkCanada

Above example generates table with 4 rows and 3 columns.

3. Create Table From Database Query Result

We can direct generate table from database query result.

Below is an example of table generation from database query result.

$this->load->library('table');
$query = $this->db->query('SELECT * FROM my_table');
echo $this->table->generate($query);

Above code creates table from database table 'my_table'.

4. Example of add_row() and set_heading() Functions

We can add row to the table using add_row() function and we can set heading using set_heading() function. See below code for the same:

$this->load->library('table');
$this->table->set_heading('RollNo','Name','City');

$this->table->add_row('1','Jignesh','Rajkot');
$this->table->add_row('2','John','Washington');
$this->table->add_row('3','Mark','Canada');

echo $this->table->generate();

We can also use array like below code:

$this->table->add_row(array('1','Jignesh','Rajkot'));


5. Example of make_columns() Function

This function creates multi-dimensional array with depth equal to the number of columns desired(second argument). This function takes two argument one is one-dimensional array and second is number of columns required in the table.

Example
$list = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve');
$newlist = $this->table->make_columns($list, 3);
$this->table->generate($newlist);

// Above code generates following code.

<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td>one</td><td>two</td><td>three</td>
</tr>
<tr>
<td>four</td><td>five</td><td>six</td>
</tr>
<tr>
<td>seven</td><td>eight</td><td>nine</td>
</tr>
<tr>
<td>ten</td><td>eleven</td><td>twelve</td>
</tr>
</table>


OUTPUT:

onetwothree
fourfivesix
seveneightnine
teneleventwelve


6. Function Reference of Table Class

$this->table->generate()

This function is already used in above example. generate() function generates/creates table. To print, use echo statement.

$this->table->set_caption()

This function is used to set caption of the table.

$this->table->set_caption('Student Details');

$this->table->set_heading()

This function is also already used in above example. This function sets heading, like <th> tag in HTML.

$this->table->add_row()

This function creates row in the table. See above example, we already used add_row() function.

If we want to set attribute to particular cell, then we have to use associative array like below:

$cell = array('data'=>'Red','class'=>'mystyle','colspan'=>2);
$this->table->add_row($cell,'Green','Blue');

// Above code generates following HTML code

<td class="mystyle" colspan="2">Red</td>
<td> Green </td>
<td> Blue </td>

$this->table->make_columns()

Example of this function we already discussed. This function creates multi-dimensional array with desired number of columns.

$this->table->set_template()

We can create own template. See below example:

$tmpl = array('table_open'=>'<table border="1" cellpadding="2" cellspacing="1" class="mytable">');
$this->table->set_template($tmpl);

$this->table->set_empty()

Using this function, we can set default value for any table cells that are empty.

$this->table->set_empty("&nbsp;");

$this->table->clear()

This function clears table heading and row data.

If you want to create table using HTML <table> tag then click on following link:

Read How To Create Table In HTML

Conclusion:

CodeIgniter Table creation is very simple. But if you are not comfortable with this CodeIgniter Table Class then use simple table tag of HTML.

Thursday 13 March 2014

CodeIgniter Reserved Names

This post is about Reserved Names in CodeIgniter. Reserved names are names that are used in internal operations and developer can not use that names.

Reserved Words In CodeIgniter
Reserved Names CodeIgniter

In CodeIgniter, some controller names, function names, variable names, and constant names are reserved, so developer/programmer can not use that names.

1. Reserved Constants In CI


Constants are variable names with fixed/constant value. It should be in capital letter. Constants are fixed, we can not change value of constants.


Following are list of reserved constants in CodeIgniter:
  • ENVIRONMENT
  • EXT
  • FCPATH
  • SELF
  • BASEPATH
  • APPPATH
  • CI_VERSION
  • FILE_READ_MODE
  • FILE_WRITE_MODE
  • DIR_READ_MODE
  • DIR_WRITE_MODE
  • FOPEN_READ
  • FOPEN_READ_WRITE
  • FOPEN_WRITE_CREATE_DESTRUCTIVE
  • FOPEN_READ_WRITE_CREATE_DESTRUCTIVE
  • FOPEN_WRITE_CREATE
  • FOPEN_READ_WRITE_CREATE
  • FOPEN_WRITE_CREATE_STRICT
  • FOPEN_READ_WRITE_CREATE_STRICT

2. Reserved Variables In CI

Variables are names given to the values. We can change value of variables.

There are following reserved variables in CodeIgniter:
  • $config
  • $mimes
  • $lang

3. Reserved Functions In CI

Function is a few line of codes and reduces redundancy in application.

In CodeIgniter there are following reserved functions that developer / programmer can't create such functions:
  • is_really_writable()
  • load_class()
  • get_config()
  • config_item()
  • show_error()
  • show_404()
  • log_message()
  • _exception_handler()
  • get_instance()

4. Reserved Controller In CI

In CodeIgniter, controller is a special class and works as intermediary between views and model.


Following are the reserved controller names in CodeIgniter, programmer / developer can't use it:
  • Controller
  • CI_Base
  • _ci_initialize
  • Default
  • index

Conclusion:

Above listed names are reserved names in CodeIgniter, so developer / programmer should have to take care about naming controller name, function name, variable name, or constant name.

Tuesday 11 March 2014

How To Create Session In CodeIgniter

1. What is Session?

Session maintains a user's state and tracks user's activity while user browse the website. We have to maintain session manually because HTTP is a stateless protocol.

How To Create Session
Session Creation In CodeIgniter


2. Session Initialization

To avail session in all pages of website then first we have to initialize Session class.


We can initialize Session class as below:

$this->load->library('session');

After above statement, now we can access session library using '$this->session'.

Created session saved in the cookie.

3. What Session Data Contain?

In CodeIgniter, session is just an array and contains following information:
  • User's unique session id (Hashed with MD5)
  • User's IP address
  • User's User Agent data
  • 'last activity' time stamp
For example
[array]
(
    'session_id' => random hash,
    'ip_address' => 'user IP address',
    'user_agent' => 'user agent data',
    'last_activity' => timestamp
)

Above data is available by default.

4. How To Add Custom Data To Session?

We can store our own data in the user's cookie. There are two ways to add data to the session, listed below:
  • Using array
  • One value at a time
Let's see one example of using array:

$userdata=array(
    'username' => 'xyzname',
    'emailid' => 'xyz@abc.com'
);
$this->session->set_userdata($userdata);

Let's see one example of one value at a time:

$this->session->set_userdata('username','xyzname');
$this->session->set_userdata('emailid','xyz@abc.com');

Cookie can only hold 4KB of data, so careful about data size.

5. How To Retrieve/Get Session Data?

Session data can be retrieved using all_userdata() or userdata() functions.

$this->session->all_userdata();

$this->session->userdata('session-key-name');

all_userdata() function returns an associative array as follows:

Array
(
   [session_id] => d1f7ddfa2c71b9aba777763c74047c3c
   [ip_address] => '127.0.0.1'
   [user_agent] => Mozilla/5.0 (Windows NT 6.1; rv:27.0) Gecko/20100101 Firefox/27.0
   [last_activity] => 1394467693
)

To extract individual session then use userdata() function as described below:

$this->session->userdata('user_name')

In above example, session key is 'user_name'.

6. How To Remove/Unset Session Data?

To remove/unset session data unset_userdata() function is used. Provide session key to unset_userdata() function.

If we want to remove/unset particular session then provide that session key.

For example:
$this->session->unset_userdata('username');
$this->session->unset_userdata('emailid');

If we want to remove/unset session using associative array then consider following example:

$array_data = array('username'=>'','emailid'=>'');
$this->session->unset_userdata($array_data);

7. How To Destroy Session?

If we want to destroy current session then use following function:

$this->session->sess_destroy();

This function will destroy current session.

8. About Flashdata

Flashdata is useful when we want to display informational or status messages like 'your data is saved', 'data is retrieving', '5 record deleted', etc.

Flashdata is only available to the next server request then after automatically cleared.

How To Add Flash Data

$this->session->set_flashdata('item','value');

We can also pass an array to the function same as set_userdata().

Retrieve/Read Flash Data

To retrieve flashdata we need flashdata() function as described below:

$this->session->flashdata('item');

We can preserve flashdata through an additional request using keep_flashdata() function.

$this->session->keep_flashdata('item');

In CodeIgniter, session management is very easy. If you find any difficulty then comment below.

Saturday 8 March 2014

How To Create Form In HTML

Hello friends here is a descriptive tutorial about form creation in HTML. To create form in HTML <form> tag is used. Forms are useful in creation of student registration, employee registration, login, etc.

How To Create Form
Create HTML Form