Find second and fourth saturday's of the month in PHP-MySql

Find second and fourth saturday's of the month in PHP-MySql


In this section, I have created simple script in PHP to find second(2nd) and fourth(4th) Saturday of the month.

<?php
// Mysql Connection
$conn = mysql_connect('localhost','root','');
if (!$conn) {
die('Could not connect to MySQL: ' . mysql_error());
}
echo 'Connection OK'; mysql_close($conn);

// Select Database
mysql_select_db("test");

// Array of the Month's
$month_array=array("jan","Feb","Mar","Apr","May","Jun","july",'Aug',"Sep","Oct","Nov","Dec");

// Array of the Years's
$year_array=array("2013","2014");

foreach($year_array as $year)
{

foreach($month_array as $month)
{
echo $second=date('Y-m-d', strtotime("second sat of $month $year"));
echo "<br>";
echo $fourth=date('Y-m-d', strtotime("fourth sat of $month $year"));
echo "<br>";

}
}

?>



You can use this PHP script to find second and fourth saturday of particular month and year.


Bookmark and Share

php.ini configuration file Default values

php.ini configuration file Default values

The PHP configuration file(php.ini) is read when PHP is initialized. php.ini includes the core php.ini directives you can set these directives to configure your PHP setup.php.ini will be located at /etc/php5/apache2/php.ini or /etc/php.ini

php.ini configuration file Default values

php.ini default values:

display_errors
;Default Value: On
This determines whether errors should be printed to the screen or not.

---------------------------------------------------------------------
error_reporting
;Default Value: E_ALL & ~E_NOTICE

// Turn off all error reporting
error_reporting(0);

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

// Report all PHP errors
error_reporting(-1);

--------------------------------------------------------------------------------
max_input_time
;Default Value: -1 (Unlimited)
This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET.

-----------------------------------------------------------------------------------
short_open_tag
;Default Value: On
whether the short form ( ) of PHP's open tag should be allowed
---------------------------------------------------------------------------------
max_execution_time = 30
Maximum execution time of each script, in seconds
----------------------------------------------------------------------------------
file_uploads :"1"
Whether or not to allow HTTP file uploads.
---------------------------------------------------------------------------------
upload_max_filesize : 2M
The maximum size of an uploaded file.

-------------------------------------------------------------------------------
max_file_uploads :20
The maximum number of files allowed to be uploaded simultaneously.

------------------------------------------------------------------------------
max_input_vars : 1000
How many input variables may be accepted .
-------------------------------------------------------------------------------
upload_tmp_dir : NULL
The temporary directory used for storing files when doing file upload.
--------------------------------------------------------------------------------
error_log
Name of the file where script errors should be logged.
------------------------------------------------------------------------------
log_errors : "0"
Tells whether script error messages should be logged to the server's error log
-----------------------------------------------------------------------------------
memory_limit : 128M
This sets the maximum amount of memory in bytes that a script is allowed to allocate.
-----------------------------------------------------------------------------------
session.gc_maxlifetime : 1440
session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage'.
------------------------------------------------------------------------------------
session.cookie_lifetime : 0
session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser.
The value 0 means "until the browser is closed." Defaults to 0.
---------------------------------------------------------------------------------

Check List of php.ini directives: http://php.net/manual/en/ini.list.php


Bookmark and Share

MySQL delete duplicate rows from table using single query

MySQL delete duplicate rows from table using single query:

In this article,I will show how to delete duplicate records from table using single MySQL Query.

MySQL delete duplicate rows from table using single query

Example:

I have a table contain departments (department_table).

CREATE TABLE IF NOT EXISTS `department_table` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `department` VARCHAR(250) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


Department table contains duplicate records of department.

id     Department
1 Sales
2 R&D
3 Support
4 Account
5 Sales

You can use following query to remove duplicate records from table using single query:

DELETE D2
FROM   department_table D1
JOIN   department_table D2 ON (D2.department = D1.department )  AND( D2.id > D1.id); 

OUTPUT:

id     Department
1 Sales
2 R&D
3 Support
4 Account

I hope this MySQL query will help you to remove duplicate records from table.


Bookmark and Share

Most useful jQuery functions

Most useful jQuery functions

In this article, I have provided list of most commonly used jQuery functions.


List of jQuery functions:


1. jQuery Selectors:

//--- COMMON JQUERY SELECTORS ---//
// get element by id
$("#ElementID").whatever();

// get element by css class
$(".ClassName").whatever();

// get elements where id contains a string
$("[id*='value']").whatever();

// get elements where id starts with a string
$("[id^='value']").whatever();

// get elements where id ends with a string
$("[id$='value']").whatever();

// get all elements of certain type (can use "p", "a", "div" - any html tag)
$("div").whatever();



2. jQuery Toggle, Show and Hide Functions:

//--- JQUERY TOGGLE/SHOW/HIDE ---//
// toggle hide/show of an element
$("#DivID").toggle(1000);

// do something when animation is complete
$("#DivID").toggle(1000, function () {
alert("Toggle Complete");
});


// hide an element
$("#DivID").hide(1000);

// do something when animation is complete
$("#DivID").hide(1000, function () {
alert("Hide Complete");
});


// show an element
$("#DivID").show(1000);

// do something when animation is complete
$("#DivID").show(1000, function () {
alert("Show Complete");
});



3. jQuery Slide Functions:

//--- JQUERY SLIDE - SLIDE AN ELEMENT IN AND OUT ---//
// toggle slide up and down
$("#DivID").slideToggle(1000);

// do something when animation complete
$("#DivID").slideToggle(1000, function () {
alert("Slide Toggle Complete");
});

// slide up
$("#DivID").slideUp(1000);

// do something when animation is complete
$("#DivID").slideUp(1000, function () {
alert("Slide Up Complete");
});

// slide down
$("#DivID").slideDown(1000);

// do something when animation is complete
$("#DivID").slideDown(1000, function () {
alert("Slide Down Complete");
});



4. jQuery Fade Functions:

//--- JQUERY FADE - FADE AN ELEMENT IN, OUT & TO ---//
// fade in
$("#DivID").fadeIn(1000);

// do something when animation complete
$("#DivID").fadeIn(1000, function () {
alert("Fade In Complete");
});

// fade out
$("#DivID").fadeOut(1000);

// do something when animation is complete
$("#DivID").fadeOut(1000, function () {
alert("Fade Out Complete");
});

// fade to (fades to specified opacity)
$("#DivID").fadeTo(1000, 0.25);

// do something when animation is complete
$("#DivID").fadeTo(1000, 0.25, function () {
alert("Fade To Complete");
});



5. jQuery Animate Functions:

//--- ANIMATE (EXAMPLE USES OPACITY, BUT CAN USE ANY CSS PROPERTY. ---//
//--- NOTE SOME MY REQUIRE THE USE OF A PLUGIN SUCH AS JQUERY COLOR ANIMATION PLUGIN. ---//
$("#DivID").animate({ opacity: 0.25 }, 1000);

// do something when animation complete
$("#DivID").animate({ opacity: 0.25 }, 1000, function () {
alert("Opacity Animation Complete");
});



6. Add & Remove CSS Classes:

//--- ADD & REMOVE CSS CLASSES ---///
// add css class
$("#DivID").addClass("newclassname");

// remove css class
$("#DivID").removeClass("classname");

// add & remove class together
$("#DivID").removeClass("classname").addClass("newclassname");

// add & remove multiple classes
$("#DivID").removeClass("classname classname2").addClass("newclassname newclassname2");



7. Get & Set Textbox Values: 

//--- GET & SET TEXTBOX VALUE ---//
//--- CAN ALSO BE USED ON ANY OTHER ELEMENT THAT HAS A VALUE PROPERTY ---//
// get the value of a textbox
var TextboxValue = $("#TextboxID").val();

// set the value of a textbox
$("#TextboxID").val("New Textbox Value Here");



8. Get & Set Element's HTML:

//--- GET & SET HTML OF ELEMENT ---//
// get element html
var DivHTML = $("#DivID").html();

// set element html
$("#DivID").html("This is the new html
");



9. Get & Set Element's Text:

//--- GET & SET TEXT OF ELEMENT ---//
// get text of element
var DivText = $("#DivID").text();

// set text of element
$("#DivID").text("This is the new text.");



10. Get & Set Element's Width & Height:

//--- GET & SET ELEMENT'S WIDTH & HEIGHT
// get element height
var ElementHeight = $("#DivID").height();

// set element height
$("#DivID").height(300);


// get element width
var ElementWidth = $("#DivID").width();

// set element width
$("#DivID").width(600);



11. EXTRA: Change Element's CSS Property

//--- CHANGE AN ELEMENT'S CSS PROPERTY ---//
$("#DivID").css("background-color", "#000");
$("#DivID").css("border", "solid 2px #ff0000");


12. each() jQuery API function:

$("#DivID").each(function(index, value) {
    console.log('DivID' + index + ':' + $(this).attr('id'));
});


Here is the list of most commonly used jQuery API functions:

find(): Selects elements based on the provided selector string
hide(): Hides an element if it was visible
show(): Shows an element if it was hidden
html(): Gets or sets an inner HTML of an element
append() Injects an element into the DOM after the selected element
prepend() Injects an element into the DOM before the selected element
on(): Attaches an event listener to an element
off() Detaches an event listener from an element
css(): Gets or sets the style attribute value of an element
attr() Gets or sets any attribute of an element
val(): Gets or sets the value attribute of an element
text(): Gets the combined text of an element and its children
each(): Iterates over a set of matched elements


Bookmark and Share

Yahoo Weather API PHP Script Example/Widget

Yahoo Weather API PHP Script Example/Widget  

In this example, I will show how to create weather application using Yahoo Weather API.Yahoo Weather API allows developers and programmers to get up-to-date weather information for your location.Yahoo Weather API provides local & long range Weather Forecast, Current Conditions, weather icons and two day future.

<?php
/*

Example: Yahoo! Weather API Example Using SimpleXML in PHP.

The base URL for the Weather RSS feed is
http://weather.yahooapis.com/forecastrss

Parameters
w WOEID 
e.g: w=111111

u Units for temperature
f: Fahrenheit
c: Celsius 
e.g.: u=c

*/


$city="bangalore";

$result1 = file_get_contents("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22$city%22&format=xml");
$xml1 = simplexml_load_string($result1);
 $woeid=$xml1->results->place->woeid;

if($woeid!="")
{
$fetchData = file_get_contents("http://weather.yahooapis.com/forecastrss?w=$woeid&u=c");
$xmlData = simplexml_load_string($fetchData);
$location = $xmlData->channel->xpath('yweather:location');


if(!empty($location))
{

foreach($xmlData->channel->item as $data)
{
$current_condition = $data->xpath('yweather:condition');
$forecast = $data->xpath('yweather:forecast');
$current_condition = $current_condition[0];
echo "
<table width=40% border=1 align=center>
<tr>
<td align=center style='background-color:yellow'>
  <h1>{$location[0]['city']}, {$location[0]['region']}</h1>
<small>Date: {$current_condition['date']}</small>
<h2>Current Temprature</h2>
<p>
<span style=\"font-size:64px;font-color:red; font-weight:bold;\">{$current_condition['temp']}°C</span>
<br/>
<img src=\"http://l.yimg.com/a/i/us/we/52/{$current_condition['code']}.gif\" style=\"vertical-align: middle;\"/>
{$current_condition['text']}
</p>
<h2>Forecast</h2>
<b>{$forecast[0]['day']}</b> : {$forecast[0]['text']}. <b>High:</b> {$forecast[0]['high']} <b>Low:</b> {$forecast[0]['low']}
<br/>
<b>{$forecast[1]['day']}</b> - {$forecast[1]['text']}. <b>High:</b> {$forecast[1]['high']} <b>Low:</b> {$forecast[1]['low']}
</p>
</td>
</tr></table>
";
}
}
else
{
echo "<h1>please try a different City.</h1>";
}


}
else
{
echo "<h1>Please try a different City.</h1>";
}

?>



OUTPUT


I hope above example will help you to get weather Information for your location.
For more details check : http://developer.yahoo.com/weather


Bookmark and Share