Monday, 05 June 2017 07:23

How to Add JQuery In Joomla

Including Jquery in your joomla 3 to load Joomla Calender

Resolving conflict with JQuery when including jquery library directly.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script> $(document).ready(function(){ $(".advance").click(function(){ $("div#advanceoption").slideToggle(); }); }); </script>

The method above failed to display Joomla Calender popup but toogle slider works properly .

 

Solution

With this method below both joomla calender pop up and toogle slider works perfectly

<?php
$doc = JFactory::getDocument(); JHtml::_('jquery.framework'); $doc->addScriptDeclaration(' jQuery(document).ready(function () { jQuery(".advance").click(function(){ jQuery("div#advanceoption").slideToggle(); }); }); ');
?>
Select Record in MySql that Matches Month and Year
Example
SELECT * FROM tb_procedure WHERE MONTH(code_date) = 6 AND YEAR(code_date) = 2017;

The SQL Syntax above will select record whose Month is June and Year is 2017.

 

Result
Month and Year Select MySql

 

Syntax

date_default_timezone_set(timezone);

The date_default_timezone_set() function set the default timezone.This means that your date and time will assume the set time zone. 

Check time zone list here

Example 1
<?php
date_default_timezone_set("Asia/Dubai");
echo date_default_timezone_get();
?>

 

Result
Asia/Dubai

 

Example 2

The example below will display date output with php default time zone and time zone set to Asia/Dubai which is +4 GMT.Note the time difference.

<?php
echo date("Y-m-d H:i:s");
echo "<br>"; date_default_timezone_set("Asia/Dubai"); echo date("Y-m-d H:i:s"); ?>

 

Result
2017-05-29 08:48:03
2017-05-29 12:48:03
Monday, 29 May 2017 07:24

PHP date_format() Function

Syntax

date_format(object,format);

This function returns a formatted date.

 

Example
<?php
$Objdate=date_create("2017-05-29");
echo date_format($Objdate,"Y/m/d H:i:s");
?>
Result
 
 2017/05/29 00:00:00
 
Monday, 29 May 2017 06:57

PHP Date Function

Syntax

date(format,timestamp)

Commonly used characters for date

d - The day of the month (01 to 31)

m - Month (01 to 12)

Y - Year in digits usually 4 digits (e.g 1988)

 l  - (small letter L ) - Day of the week

 

Example

<?php echo "Current date is " . date("Y/m/d") . "<br>"; echo "Current date is " . date("Y.m.d") . "<br>";
echo "Current date is " . date("Y-m-d") . "<br>";
echo "Current day is " . date("l");
?>


Result
 
Current date is 2017/05/29
Current date is 2017.05.29
Current date is 2017-05-29
Current day is Monday
 

Note: This will display the current date e.g output may not be the current date

Saturday, 20 May 2017 14:13

Using PHP str_replace() Function

The str_replace()  function is used to replace a character with another character in PHP.

Syntax

str_replace(search,replace,string,count);

find = Value to search in the string 
replace = Value to replace the find with
string   =  String to be search
count = Variable that counts the number of replacements (Optional)

 

Example 1

In the example below we searched for the value Dublin and replaced with Galway

 
<?php 
 $string = "Welcome to Dublin"; 
 echo str_replace("Dublin","Galway",$string);
?>
 
Result
 
Welcome to Galway
 


Replacing with empty value.

Example 2

We replaced the value Mr with an empty value 

<?php 
$string = "Welcome home Mr Green"; $search = "Mr";
 $replace = "";
echo str_replace($search,$replace,$string);
?>
Result
 
Welcome home Green
 
Example 3

Searching an array and replacing its value with another value

<?php 
$myarr = array("dog","cow","donkey","cat");
print_r(str_replace("cow","zebra",$myarr,$i));
echo "<br>" . "Counter: $i"; //Count number of replacements
?>

In this example, we search an array $myarr  for the value "cow" and replace it with the value "zebra". 

Result
Array ( [0] => dog [1] => zebra [2] => donkey [3] => cat )
Counter: 1