Wednesday 19 November 2014

How to pass variable number of arguments to a function in PHP?

In certain cases, you may require to pass different number of arguments to a function in PHP scripts. Let us consider a case where you want to calculate average of a set of values using a function. Number of values in the set may vary in each call to the function. PHP provides a mechanism to pass different number of arguments to a function and process the arguments from the function by using the following functions.

func_num_args() - Returns the number of arguments passes to the function

func_get_args() - Returns the arguments passed to the function as an array

func_get_arg($arg_num) - Returns the argument at the $arg_num th position or index . Starting index is 0.



You can see the PHP implementation of the above problem here.

Tuesday 18 November 2014

Which are the top 10 websites in the world?



As per alexa (www.alexa.com) ranking www.google.com, worlds No. 1 search engine, is the top ranked website in the world. Second place goes to www.facebook.com, the new generation social media website.

Here is the list of top 10 websites of the world as per the records of www.alexa.com.
 

How to create your own Forms with custom Paper Sizes for Printers in Windows?

Windows provides an option to create your own Forms / Paper Size like A4, A3, etc.  with custom size and name for printing. You can add new forms to the list of Forms that will be listed in the Paper Tab of Print Dialog Box. Here is the step by step procedure for creating your own Forms.

Monday 17 November 2014

How to apply alternate background color for rows of an HTML table using CSS

In some cases you may want to apply alternate background color for each row of an HTML table.Using CSS3 it is easy to apply alternate color for rows in an HTML table.

Create styles using CSS3 and specify background color by using nth-child(even) and nth-child(odd) selectors.


You can see the CSS3 implementation of the above problem here.

How to apply alternate background color for rows of an HTML table using PHP Script

In some cases you may want to apply alternate background color for each row of an HTML table. Using a simple script you can solve the problem. You can just apply one color for every odd row and apply another color for every even row. Check whether current row is even or odd by using a rowcount variable and check the result of rowcount mod 2  (ie. rowcount % 2) is 0 or not and change the value of background color attribute accordingly.

If rowcount % 2 is 0 then it is a even row and apply one color for that, other wise it is odd row and apply another color.

  $bgcolor = "#ffffff";
   if ($i % 2 == 0)
              $bgcolor = "#ECD23F";




You can see the PHP implementation of the above problem here.

Monday 10 November 2014

Page wise or paginated listing of data from a database table using PHP

This example demonstrates how data from a database table  is displayed as different pages  in a webpage.

In this example records per page is stored in a variable $pagesize and it is set to 15 (you can change it as per your requirements). For each page the query is selecting only the required 15 records and displays it. 
Starting record of the given  page ($pageno) is calculated by the following expression.

 $start_rec = (($pageno-1) * $pagesize) ;

Query to select required number of records starting from start_rec is given below. To specify the starting record and number of records in SQL query the LIMIT clause is used.

Wednesday 5 November 2014

How to read, write, update and list data from a database using Java - JDBC

JDBC is a Java database connectivity technology to access databases. This technology is an API for the Java programming language that defines how a client may access a database. It provides methods for querying and updating data in a database A JDBC-to-ODBC bridge enables connections to any ODBC-accessible data source

The example given below demonstrate how to access a database using JDBC. In this example we uses three classes.