How to make a calendar by PHP Code

<?php
$monthNames = Array(“January”, “February”, “March”, “April”, “May”, “June”, “July”,
“August”, “September”, “October”, “November”, “December”);
?>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>

<body>
<?php
if (!isset($_REQUEST[“month”])) $_REQUEST[“month”] = date(“n”);
if (!isset($_REQUEST[“year”])) $_REQUEST[“year”] = date(“Y”);
?>
<?php
$cMonth = $_REQUEST[“month”];
$cYear = $_REQUEST[“year”];

$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;

if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear – 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<table width=”200″>
<tr align=”center”>
<td bgcolor=”#999999″ style=”color:#FFFFFF”>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”50%” align=”left”>  <a href=”<?php echo $_SERVER[“PHP_SELF”] . “?month=”. $prev_month . “&year=” . $prev_year; ?>” style=”color:#FFFFFF”>Previous</a></td>
<td width=”50%” align=”right”><a href=”<?php echo $_SERVER[“PHP_SELF”] . “?month=”. $next_month . “&year=” . $next_year; ?>” style=”color:#FFFFFF”>Next</a>  </td>
</tr>
</table>
</td>
</tr>
<tr>
<td align=”center”>
<table width=”100%” border=”0″ cellpadding=”2″ cellspacing=”2″>
<tr align=”center”>
<td colspan=”7″ bgcolor=”#999999″ style=”color:#FFFFFF”><strong><?php echo $monthNames[$cMonth-1].’ ‘.$cYear; ?></strong></td>
</tr>
<tr>
<td align=”center” bgcolor=”#999999″ style=”color:#FFFFFF”><strong>S</strong></td>
<td align=”center” bgcolor=”#999999″ style=”color:#FFFFFF”><strong>M</strong></td>
<td align=”center” bgcolor=”#999999″ style=”color:#FFFFFF”><strong>T</strong></td>
<td align=”center” bgcolor=”#999999″ style=”color:#FFFFFF”><strong>W</strong></td>
<td align=”center” bgcolor=”#999999″ style=”color:#FFFFFF”><strong>T</strong></td>
<td align=”center” bgcolor=”#999999″ style=”color:#FFFFFF”><strong>F</strong></td>
<td align=”center” bgcolor=”#999999″ style=”color:#FFFFFF”><strong>S</strong></td>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date(“t”,$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth[‘wday’];
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ) echo “<tr>n”;
if($i < $startday) echo “<td></td>n”;
else echo “<td align=’center’ valign=’middle’ height=’20px’>”. ($i – $startday + 1) . “</td>n”;
if(($i % 7) == 6 ) echo “</tr>n”;
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>

Demo Output –

API Integration Using Php code

PHP has a powerful JSON(Api Format) parsing mechanism, which, because PHP is a dynamic language, enables PHP developers to program against a JSON object graph in a very straightforward way. Example 9 shows a PHP page that sends a request to the JSON interface using the file_get_contents API to call the JSON endpoint, and the json_decode function to turn the results into an object graph that can be walked and turned into HTML.

Example 9: Using the API with PHP

<html>
<head>
   <link href="styles.css" rel="stylesheet" type="text/css" />
 <title>PHP Bing</title>
</head>
<body><form method="post" action="<?php echo $PHP_SELF;?>"> 
 Type in a search:<input type="text" id="searchText" name="searchText" value="<?php 
 if (isset($_POST['searchText'])){
  echo($_POST['searchText']); }
  else { echo('ashish');}
  ?>"/>
        <input type="submit" value="Search!" name="submit" id="searchButton" />
<?php
if (isset($_POST['submit'])) {
$request = 'http://api.search.live.net/json.aspx?Appid=<YourAppIDHere>&sources=image&query=' . urlencode( $_POST["searchText"]);
$response  = file_get_contents($request);
$jsonobj  = json_decode($response);
echo('<ul ID="resultList">');                    
                
foreach($jsonobj->SearchResponse->Image->Results as $value)
{
echo('<li class="resultlistitem"><a href="' . $value->Url . '">');
echo('<img src="' . $value->Thumbnail->Url. '"></li>');

}
echo("</ul>");
} ?>
</form>
</body>
</html>

Show and Hide div through javascript.

The only change from above is the JavaScript area. You will notice that the extra space is no longer reserved in the div as it is with the show(), hide() method.

JavaScript:

  $('#d3show').click(function() {
      $('#d1').css('display', 'none');
      $('#d2').css('display', 'none');
      $('#d3').css('display', 'inline');
    });

    $('#d2show').click(function() {
      $('#d1').css('display', 'none');
      $('#d2').css('display', 'inline');
      $('#d3').css('display', 'none');
    });

    $('#d1show').click(function() {
      $('#d1').css('display', 'inline');
      $('#d2').css('display', 'none');
      $('#d3').css('display', 'none');
    });

Update Record in php

 Update simple Record

if(isset($_POST[“update”]))
{
$rid = $_POST[‘id’];
$finame = $_POST[“fname”];
$query1 = “UPDATE users SET FirstName= ‘”.$_POST[fname].”‘, LastName= ‘”.$_POST[lname].”‘, Mobn= ‘”.$_POST[mobile].”‘, Email='”.$_POST[email].”‘ WHERE  Id='”.$rid.”‘”;   // Update Query
$up = mysql_query($query1,$con);
if($up)
{

die(“location.href = ‘SearchandUpdate.php'”);  //if header Function not then use die function.  this use redirect another page.

//header function – header(‘Location:SearchandUpdate.php’); same use die function.

}
else
{
echo “Error : Data not Updated !!!”;    //Error  message.
}
}

multiple div show and hide through database using dropdown list

$con = mysql_connect(“localhost”,”root”,””) or die(“mysql conn. error”);
mysql_select_db(‘databasename’) or die(“mysql conn. error”); // database connection

if(isset($_GET[‘Name’]))  //get  value through URL
{
$name = $_GET[‘Name’];
$query = “select * from cad where Name = ‘”.$name.”‘”;
$qu = mysql_query($query, $con);
while($res= mysql_fetch_array($qu))
{
if($res[‘ptype’] == ‘Half Yearly Payment’)
{

$Name = $res[“Name”];
$ptype = $res[“ptype”];
}
else if($res[‘ptype’] == ‘Monthly Payment’)
{

$Name = $res[“Name”];
$ptype = $res[“ptype”];

}
else if($res[‘ptype’]==’Quarterly Payment’)
{

$Name = $res[“Name”];
$ptype = $res[“ptype”];
}
else
{
$Name = $res[“Name”];

$ptype = $res[“ptype”];
}
}
}

// html code

<select class=”drop” id=”payment” name=”ptype” >
<option  id=”S_0″ value=”Monthly Payment”>Monthly Payment</option>
<option  id=”S_1″ value=”Quarterly Payment”>Quarterly Payment</option>
<option  id=”S_2″ value=”Half Yearly Payment”>Half Yearly Payment</option>
<option  id=”S_3″ value=”Yearly Payment”>Yearly Payment</option>
</select>

// multiple div show and hide php code

if($res[‘ptype’]== ‘Monthly Payment’)

{

  echo  $Name;    

   echo $ptype;

}

if($res[‘ptype’]== ‘Quarterly Payment’)

{

  echo  $Name;    

   echo $ptype;

}

if($res[‘ptype’]== ‘Half Yearly Payment’)

{

  echo  $Name;    

   echo $ptype;

}

if($res[‘ptype’]== ‘Yearly Payment’)

{

  echo  $Name;    

   echo $ptype;

}