This is how you add a calendar / date picker to Joomla form.

add the following code to your
xx.html.php class



$document = &JFactory::getDocument();
$document->addScript("includes/js/joomla.javascript.js");

JHTML::_('behavior.calendar');



and add the following code to the default.php template file








All those codes above will have a calendar / date picker close to the input field.

Enjoy your coding.

Debugging view of 2D array

If you are in a position to have a better view of 2 dimensional array then try this



$fruits["apple"] = array("Canada","US","Extra");


print_r($fruits) won't show a better view but the following way would show a clear view of arrays and values



echo "
";
print_r($fruits);
echo "
";



Enjoy.
cheers.

If you are trying to redirect a dynamic URL follow the steps to do it.


RewriteCond %{QUERY_STRING} ^product_id=(.*)$
RewriteRule ^product_view\.php$ /products/%1? [R=301,L]



The above statements would do the following,

http://www.example.com/product_view.php?product_id=4

redirected to

http://www.example.com/products/4

Hope it helps someone.
cheers.

If you are trying to select records whose ids are not present in the other table,

eg: articles table has article_id, categorized table has article_id and cat_id.
If you are trying to select the article that is not categorized yet



SELECT * FROM articles WHERE article_id NOT IN ( SELECT article_id FROM categorized );



That will solve your problem.

SQL to filter duplicate records

If you are trying to filter out duplicate records from your table.



SELECT DISTINCT column_name,id FROM table_name
GROUP BY coulumn_name
HAVING COUNT(column_name) > 1



The above sql would filter out duplicate records with their ids.

cheers.

SQL to get count of records

This is for MySQL I have no idea about other DBs



$query = mysql_query("SELECT count(*) FROM accounts");
$ctr = mysql_result($query,0,0);


Hope it helps someone.

If you happened to see ^M at end of every line of your code, it's a real pain. You can remove the character from the file somehow.

from your command line (Linux)

1) sed -e 's/^M//g' index.php > ind.php
[ ctrl v + ctrl M would give your ^M char on command line ]

2) mv ind.php index.php

Now, your index file is free of ^M characters. Enjoy coding.

Modify User Registration of Joomla

If you'd like to change user registration page of Joomla, follow the following steps to accomplish it.

1) Change in template file (under components/user/)
2) modify /libraries/joomla/user/user.php
3) modify /libraries/joomla/database/table/user.php

and also modify users table of joomla using any db admin scripts eg:phpMyadmin

Modify those files as per your request, you will see a modified user registration page of Joomla.

If you are looking forward to enable Javascript in different browsers, just check whether it's disabled first by visiting the site.

www.isjavascriptenabled.com

That would tell you whether it's enabled or disabled

How to enable the Javascript now?

Go to the site get info as per your browser.

www.tranexp.com/win/JavaScript-enabling.htm

Redirect using mod_rewrite

if you are trying to redirect any subdomain request to the root, try the following method. The URL will not change in the address bar.

RewriteCond %{HTTP_HOST} ^business\.rootdomain\.com
RewriteCond %{REQUEST_URI} !^/business/
RewriteRule (.*) http://www.rootdomain.com/business/$1 [P]

if you get any internal error, add proxy & proxy http modules to Apache.

restart the web server,it should work now.

If you are looking forward to install SSH2, follow the link to do so. It works and save you a lots time.

http://cubiclegeneration.com/web-servers/installing-secure-shell2-ssh2-php-extension

if you experience any issue at these lines

gunzip libssh2-0.18.tar.gz

tar -xvf libssh2-0.18.tar.gz

Just remove the .gz from the end, would work.

Done.

htaccess issue with SEF URL in Joomla

On your developer box: You enabled SEF in Joomla by doing the following way:

1.rename htaccess.txt to .htaccess
2.Global Configuration -> SEO Settings (set yes to everything) and save it

Refresh your Joomla site
click on your site links - if the short url is working then everything is cool if NOT

open up your Apache config file and

add the following lines to your virtual host setup

        
AllowOverride all


save the config file and restart the apache.
DONE.

If you having trouble with your flash player in CentOS 5 ( 64 bits) then follow the link to make it work. I googled for help and found out this after a long time. It's good.

http://www.yqed.com/install-flash-player-10-centos-64-bits/

Enjoy your flash player.

isset, empty functions of PHP

Always pay attention to these functions.


$a = 0;
// isset() - treats $a as not empty
if(isset($a))
echo "a has ".$a;

// empty() - treats $a as empty

having trouble with empty() with the editor

if(empty($a))
echo "a has ".$a;


both functions will display "a has 0".

Reading a file into a string in PHP

If you'd like to get the entire content of a file into a string then follow the way



// have your filename with path
$file_name = "yourfilename.ext";
$content_string = file_get_contents($file_name);
echo $content_string; // will display the content


want to display total chars in the file?


echo strlen($content_string);


To read file into array.


// have your filename with path
$file_name = "yourfilename.ext";
$content = file($filename);
foreach($content as $content_row)
echo $content_row;


// checks postal code format L4X-1S9
$regex = '/[a-z][0-9][a-z][- ]?[0-9][a-z][0-9]$/i';
if( preg_match($regex, $zip) )
echo "Valid postal code";


// checks for 5 digit or 9 digit zip code or 12345-6789
// or 123456789
$regex = '/(^\d{5}$)|(^\d{5}-\d{4}$)|(^\d{9}$)/'
if( preg_match($regex, $zip) )
echo "Valid Zip code";

Passing a PHP array to Javascript

PHP array:


$fruits = array("Apple","Mango","Banana");

convert $fruits to Javascript array


echo 'var fruits = new Array("',join($fruits,'","'),'");';


The above statement will convert PHP array to Javascript array. This saves a lot of time.



Some Links (off programming)