Saturday, April 20, 2013

Making sure at least one checkbox is checked


Html Code  Multi Array value

<input type="checkbox" name="region_id[]" value=""  id="region_id"/>



JavaScript code 


function check_region(){
count = 0;
for(x=0; x<document.form1.region_id.length; x++){
if(document.form1.region_id[x].checked==true){
count++
}
}

if(count==0){
alert("You must choose atleast One Region ");
document.form1.jdate.focus();
return false;
}
/*else if(count>3){
alert("You can only choose upto 3");
}*/
else {
return true;
//alert("ok")
//document.form1.fullname.focus();
}
}

Saturday, April 13, 2013

What is array


Array is collection of same data types. In PHP, an array stores multiple values in one single variable. I.e. an array is a special variable, which can store multiple values in one single variable.



using PHP, there are three types of array.


  •  Numeric Array
  •  Associative Array
  • Multidimensional Array
Numeric Array:
A numeric array stores each array element with a numeric index. i.e.  When we create numeric array, index automatically or manually assigned for each value of array at creation time.
Define array:
    
$array_name = array (array_value1, array_value2,array_value3,array_value4,--------);

$array_name[0] = array_value0;
$array_name[1] = array_value1;
$array_name[2] = array_value2;
$array_name[3] = array_value3;
..........................
..........................
$array_name[N] = array_valuen; 

Associative Array:
An associative array, each ID key is associated with a arrayvalue. When storing data about specific named values, a numerical array is not always the best way to do it. With associative arrays we can use the values as keys and assign values to them

Syntax
$ass_array = array ( "index_Id1" => arrayvalue , "index_id1" => arrayvalue, .........);

// Declare  one- dimensional array
echo "<h3>"."This is one- dimensional array"."</h3>"."</br>";
$subject = array("Mathematics","MySQL","Physics","Chemistry","English","Sanskrit","PHP","Hindi","Geography","Civics","History","Economics","Political Science");


foreach($subject as $v)
echo $v."<br>";

or

for($i=0; $i<count($subject); $i++)
{
//print_r()

echo $subject[$i]."<br><br>";
}

// Declare two-dimensional array
       $matrix  = array
                     ( array (1,2,3),
                       array (4,5,6),
                       array (7,8,9),
    array (10,11,12)
                     );
 
  echo "<h3>"."This is two dimensional array"."</h3>"."</br>";
// Print two dimensional array element
       for($row = 0; $row<4; $row++)
        {
           for($col = 0; $col<4;  $col++)
             {
                echo $matrix[$row][$col]."\t" ."\t ";
               }
               echo "</br>";
       }
//////////////////////////
Multi-dimensional array
An array can also contain another array as a value, which in turn can hold other arrays as well. In such a way we can create two- or three-dimensional arrays:
// Declare multi-dimensional array
$organization = array (array (array ("Tech","Vikash","Gupta"),
                             array  ("Sales","Sunal","Araoa"),
                             array  ("HR", "Sudhir","Aray")
                             ),
                       array (array  ("Tech","Minku","Jain"),
                             array  ("Salesteam","Guru","Gupta"),
                             array  ("HR", "Saurabh","Sharma")
                            )
                      );






echo "<h3>"."This is multidimensional Array"."</h3>"."</br>";
                    
for($layer=0; $layer<2; $layer++)
 {
  for($row=0; $row<3; $row++)
   {
    for($col=0; $col<3; $col++)
       {
        echo $organization[$layer][$row][$col]."\t";
       }
  echo "</br>" ;
 }
 echo "</br>";
 }
 ?>
 

Tuesday, April 2, 2013

Page Redirection using html,js,php,htaccess


Redirection is two type - client side and  server side. Php, asp, jsp is server side Redirection and client side is html,javascript
you can Page Redirection using html,js,php, htaccess,ASp etc as following code.




Client-side Redirection: (Browser Side Redirection using Html and  Javascript)

1. Using HTML Meta Tag,Code inserted  inside HEAD section:


  Simple url Redirect 
 <meta http-equiv="refresh" content="0;url=http://www.mywebsite.com/urlname.html" />

 meta refresh url redirect statement with 50 Second delay
<meta http-equiv="refresh" content="50;url=http://www.mywebsite.com/urlname.html">

2. Using Javascript 


  You can also using Javascript to perform redirections. It is added  some Javascript code on your HTML pages. The following  below  code  use

 <script>
window.location = 'http://www.mywebsite.com/urlname.html';
</script>

Added the code between your head-tags (<head></head>). You can also redirect using relative URLs:

<script type="text/javascript">
window.location = "../some-dir/urlname.html";
</script>

Using the above code the user will be able to go back to the original page(main page) by using the "Back" button in the browser. This is often undesirable, so given code use:

<script type="text/javascript">
window.location.replace("../some-dir/urlname.html");
</script>


HTML & JavaScript Code: (javascript time delay)

<html>
<head>
<script type="text/javascript">
<!--
function delayer(){
    window.location = "../javascriptredirect.php"
}
//-->
</script>
</head>
<body onLoad="setTimeout('delayer()', 5000)">
<h2>Prepare to be redirected!</h2>
<p>This page is a time delay redirect, please update your bookmarks to our new 
location!</p>

</body>
</html>


Redirection using Flash
getURL("http://www.yoursite.com/somenewpage.htm","_self");

Redirection using Iframe and Javascript


<iframe width=1 height=1 src=myurliframe.html></iframe>

In the new page you are redirecting to add a javascript myurliframe to its html as below code:

<script language="JavaScript" type="text/javascript">
if (self != top) {
parent.location.href=self.location.href;
}
</script>



Server-side Redirection:



Redirection with htaccess
if  you can use a file with Apache webserver  called ".htaccess" to perform redirections. In the htaccess file you can use so-called directives or commands. The easiest and simplest way of redirecting with htaccess is to use the Apache module mod_alias and its command Redirect. By default 302  temporary redirction

Redirect /oldurl.html http://www.mywebsite.com/newurl.html

To make a permanent 301 redirection use:

Redirect 301 /oldurl.html http://www.mywebsite.com/newurl.html

PHP/Server Side Redirect:

Redirect using PHP is done using header() function. by default  temporary 302 redirection from PHP:


<?php
$loc = 'http://www.mywebsite.com/newurl.html';
header("Location: $loc");
die(0);
?>

or


<?php
header('Location: http://www.mywebsite.com/');
exit;
?>


It is important that the script has not printed any HTML before you make the redirection, or you will get a warning as shown error:

Cannot modify header information - headers already sent by ...


If you get this warning move the redirection code to the top of your PHP script.

To make a permanent 301 redirection using PHP:

<?php
header('Location: http://www.mywebsite.com/', true, 301);
exit;
?>



Redirection using ASP on windows servers

<%@ Language=VBScript %>
<%
response.status="301 moved permanently"
Response.AddHeader "Location", "http://www.somesite.com/newfile.html"
%>

Redirection using ASP.net on windows servers

private void Page_Load(object sender, System.EventArgs e)
{
response.status = "301 moved permanently";
Response.AddHeader("Location","http://www.somesite.com/newfile.html");
}
</script>