<?xml version="1.0" encoding="UTF-8" standalone="no"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:gd="http://schemas.google.com/g/2005" xmlns:georss="http://www.georss.org/georss" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-2820984862098008600</atom:id><lastBuildDate>Fri, 01 Nov 2024 11:46:42 +0000</lastBuildDate><category>Php Questions</category><category>php</category><category>Php Questions and answers</category><category>php functions</category><category>Mysql</category><category>Mysql Questions</category><category>Java script</category><category>jquery</category><category>php tips</category><category>JavaScript</category><category>SEO techniques -Tips</category><category>CMS</category><category>Google maps API</category><category>HTML DOM</category><category>Ajax</category><category>apache</category><category>creating dynamic elements in HTML using Javascript.</category><category>elgg</category><category>functiion for cropping an images</category><category>linux</category><category>query helper</category><category>Ajax tool tips and Baloons</category><category>Comparing a date with current date</category><category>Contact Me</category><category>Creating Google map</category><category>Creating xml files using XML DOM in PHP</category><category>Dependant Selectboxes using Ajax</category><category>Displaying the  tagclouds</category><category>File upload progress meter in php</category><category>Function for browser checkin IE</category><category>Function for browser checking Mozilla</category><category>Function for super-hard array conversion</category><category>Function to checking the password's pattern and its length</category><category>Function to find filesize in KB</category><category>Function to get image width and height</category><category>GB</category><category>Inserting nodes into xml files using XML DOM in PHP .</category><category>MB</category><category>Pagination Class in PHP</category><category>Simple Ajax  Script</category><category>Social networking</category><category>Type Juggling in php?</category><category>adding new html elements using HTML DOM and JavaScript</category><category>check whether the url isvalid or not</category><category>codeigniter</category><category>fetching xml values from xml files using Simple XML</category><category>functiion for MD5 encrypting and decrypting</category><category>functiion for flipping images</category><category>function for convert an image into a thumb and displaying it</category><category>function for sub directories size</category><category>function shows the file size of  a directory</category><category>function to Convert Arabic numerals into  Roman</category><category>function to add/remove random underscore</category><category>function to calculate difference between two dates</category><category>function to check Na</category><category>function to ckeck the password length</category><category>function to create image</category><category>function to create random keys for email validation</category><category>function to create random password</category><category>function to date formate into one to another</category><category>function to find factorial</category><category>function to find random float number</category><category>function to find random password</category><category>function to find the extenstion of a file</category><category>function to generate unique  key</category><category>function to get Image info</category><category>function to resize an image</category><category>function to round a number into two</category><category>function to send an email</category><category>function to upload a file</category><category>htacess</category><category>m</category><category>packaging problem</category><category>stored functions</category><category>stored procedures</category><category>view an image on mouse over</category><category>web technics</category><category>wrapping the text by 10 charecters</category><title>phpqa</title><description>The PHP, MySql, Javascript helper. Contains helpful functions, urls, methods to handle them</description><link>http://phpqa.blogspot.com/</link><managingEditor>noreply@blogger.com (jj)</managingEditor><generator>Blogger</generator><openSearch:totalResults>170</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><xhtml:meta content="noindex" name="robots" xmlns:xhtml="http://www.w3.org/1999/xhtml"/><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-7867994030006382450</guid><pubDate>Thu, 14 Feb 2013 16:00:00 +0000</pubDate><atom:updated>2013-02-19T18:29:32.989+00:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Mysql</category><category domain="http://www.blogger.com/atom/ns#">query helper</category><title>How to select a specified number of values starting with each alphabets in mysql. </title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
How to select a specified number of values starting with each alphabets in mysql.&lt;br /&gt;
&lt;br /&gt;
Suppose you have a table named 'names', which has fields id and name, and you need to select two or three names from each alphabet and display it in a page. For example you have to select 3 names from the table, which contains the names starting with all the alphabets from a-z. ie, You will need to display 26 * 3 = 72 names.&lt;br /&gt;
&lt;br /&gt;
Here is the answer,

&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
SELECT 
 letter, 
 name 
FROM (
 SELECT 
  LEFT( name, 1 ) AS letter, 
  name, 
  @num := IF( @prev = LEFT( name, 1 ),@num +1, 1 ) AS row_num, 
  @prev := LEFT( name, 1 ) AS previous
 FROM 
  names,(
   SELECT 
    @num  :=0, 
    @prev := ''
  )  PHPQA
 ORDER BY name
 ) QAPHP
WHERE row_num &amp;lt;=3

&lt;/code&gt;
&lt;/pre&gt;
You can find its live example on following page.&lt;br /&gt;
&lt;a href="http://draft.blogger.com/%C2%A0http://sqlfiddle.com/#!2/abfd8/3"&gt;&amp;nbsp;http://sqlfiddle.com/#!2/abfd8/3&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://sqlfiddle.com/#!2/4887b/1"&gt;http://sqlfiddle.com/#!2/4887b/1&lt;/a&gt;&lt;/div&gt;
</description><link>http://phpqa.blogspot.com/2013/02/how-to-select-specified-number-of.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-6873848764588464579</guid><pubDate>Thu, 12 Jul 2012 14:32:00 +0000</pubDate><atom:updated>2012-07-12T15:43:22.712+01:00</atom:updated><title>Mysql query for searching a value, add weightage on the number of occurances and sort based on the weight-age</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Mysql query for searching a value, add weightage on the number of occurances and sort based on the weightage
&lt;br /&gt;
&lt;br /&gt;
Consider a table named 'data' which has columns named 'Name', and 'Content', We need to search these columns, if 'Name' colomn has a match it should have a weightage of '.08' and if 'Content' has a match it should have a weightage of '0.2' , 
&lt;br /&gt;
&lt;br /&gt;
Suppose 'Name' has one match and 'Content' has 3 match, then it should have a total weightage of (.08*1)+(.02*3) = .14 
&lt;br /&gt;
&lt;br /&gt;
For that we can use the following query to get the result.

&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
SELECT *
FROM (
SELECT * , (
(
length( `Content` ) - length( replace( LOWER(`Content`) , "SEARCHKEY", "" ) ) ) / length("SEARCHKEY" ) * .08
) + (
(
length( `Content` ) - length( replace( LOWER(`Content`) ,"SEARCHKEY", "" ) ) ) / length("SEARCHKEY" ) * .02
) AS weight
FROM data
)a
WHERE weight &amp;gt; 0
ORDER BY weight DESC
LIMIT 0,10
&lt;/code&gt;
&lt;/pre&gt;
&lt;/div&gt;</description><link>http://phpqa.blogspot.com/2012/07/mysql-query-for-searching-value-add.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-744262857940648714</guid><pubDate>Thu, 23 Feb 2012 14:44:00 +0000</pubDate><atom:updated>2012-02-23T14:44:02.642+00:00</atom:updated><title>Creating Custom Module in VtigerCRM</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;b&gt;&lt;i&gt;Creating a custom VtigerCRM Module
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Step 1.
&lt;br /&gt;
Download the module creation script from the VtigerCRM or copy it from below
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
name = 'Phpqa';
$module-&amp;gt;save();

// Initialize all the tables required
$module-&amp;gt;initTables();
// Initialize Webservice
$module-&amp;gt;initWebservice();

// Add the module to the Menu (entry point from UI). Will display under Tools menu
$menu = Vtiger_Menu::getInstance('Tools');
$menu-&amp;gt;addModule($module);

// Add the basic module block
$block1 = new Vtiger_Block();
$block1-&amp;gt;label = 'LBL_PHPQA_INFORMATION';
$module-&amp;gt;addBlock($block1);

// Add custom block (required to support Custom Fields)
$block2 = new Vtiger_Block();
$block2-&amp;gt;label = 'LBL_CUSTOM_INFORMATION';
$module-&amp;gt;addBlock($block2);

/** Create required fields and add to the block */
$field1 = new Vtiger_Field();
$field1-&amp;gt;name = 'Sales';
$field1-&amp;gt;label = 'Sales';
$field1-&amp;gt;table = $module-&amp;gt;basetable;
$field1-&amp;gt;typeofdata = 'V~O';
$block1-&amp;gt;addField($field1); /** Creates the field and adds to block */

// Set at-least one field to identifier of module record
$module-&amp;gt;setEntityIdentifier($field1);

$field2 = new Vtiger_Field();
$field2-&amp;gt;name = 'Name';
$field2-&amp;gt;label = 'Name';
$field2-&amp;gt;typeofdata = 'V~O';// Varchar~Optional
$block1-&amp;gt;addField($field2); /** table and column are automatically set */

$field3 = new Vtiger_Field();
$field3-&amp;gt;name = 'InvoiceType';
$field3-&amp;gt;label= 'Invoice Type';
$field3-&amp;gt;typeofdata = 'V~O'; // Date~Mandatory
$block1-&amp;gt;addField($field3);  /** table, column, label, set to default values */

$field4 = new Vtiger_Field();
$field4-&amp;gt;name = 'InvoiceID';
$field4-&amp;gt;label= 'Invoice ID';
$field4-&amp;gt;typeofdata = 'V~O';
$block1-&amp;gt;addField($field4);

/** END */

// Create default custom filter (mandatory)
$filter1 = new Vtiger_Filter();
$filter1-&amp;gt;name = 'All';
$filter1-&amp;gt;isdefault = true;
$module-&amp;gt;addFilter($filter1);

// Add fields to the filter created
$filter1-&amp;gt;addField($field1)-&amp;gt;addField($field2, 1)-&amp;gt;addField($field5, 2);

// Create one more filter
$filter2 = new Vtiger_Filter();
$filter2-&amp;gt;name = 'All2';
$module-&amp;gt;addFilter($filter2);

// Add fields to the filter
$filter2-&amp;gt;addField($field1);
$filter2-&amp;gt;addField($field2, 1);

// Add rule to the filter field
$filter2-&amp;gt;addRule($field1, 'CONTAINS', 'Test');

/** Associate other modules to this module */
//$module-&amp;gt;setRelatedList(Vtiger_Module::getInstance('Accounts'), 'Accounts', Array('ADD','SELECT'));

/** Set sharing access of this module */
$module-&amp;gt;setDefaultSharing('Private'); 

/** Enable and Disable available tools */
$module-&amp;gt;enableTools(Array('Import', 'Export'));
$module-&amp;gt;disableTools('Merge');

?&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;
Step 2 
&lt;br /&gt;
Save it in your vigercrm root folder. and run the script .
&lt;br /&gt;
Step 3
&lt;br /&gt;
Copy the desired version of sample vtigercrm module from the vtlib/ModuleDir and paste it into the /modules directory
&lt;br /&gt;
Step 4 
&lt;br /&gt;
Rename the folder name into the desired name you have given in the module creation script. (Phpqa)
&lt;br /&gt;
Step 5
&lt;br /&gt;
Rename the ModuleFile.php, ModuleFileAjax.php, ModuleFile.js to your module name. Here the ModuleFile indicates your module name. So names are like Phpqa.php, PhpqaAjax.php and PhpqaFile.js
&lt;br /&gt;
Step 6 
&lt;br /&gt;
Open the Phpqa.php and rename the class name into Phpqa.  Change the all modulename occurance into your custom module name
&lt;br /&gt;
Change the following
 &lt;br /&gt;
&lt;pre&gt; &lt;code&gt;
var $table_name = 'vtiger_phpqa';
var $table_index= 'phpqaid';

var $customFieldTable = Array('vtiger_phpqacf', 'phpqaid');

var $tab_name = Array('vtiger_crmentity', 'vtiger_phpqa', 'vtiger_phpqacf');

var $tab_name_index = Array(
 'vtiger_crmentity' =&amp;gt; 'crmid',
 'vtiger_phpqa'   =&amp;gt; 'phpqaid',
 'vtiger_phpqacf' =&amp;gt; 'phpqaid');

&lt;/code&gt;
&lt;/pre&gt;
Also the change the other listed variables in the page as per our need.
&lt;br /&gt;
Step 7
&lt;br /&gt;
Change the Language file variable based on the module name. Its located in /language folder of the module . 
 &lt;br /&gt;
&lt;pre&gt; &lt;code&gt;

'Phpqa' =&amp;gt; 'Phpqa',
'LBL_CUSTOM_INFORMATION' =&amp;gt; 'Custom Information',
'LBL_PHPQABLOCK_INFORMATION' =&amp;gt; 'Phpqa Block Information'

 &lt;/code&gt;
 &lt;/pre&gt;
&lt;br /&gt;
Step 8
&lt;br /&gt;
You can see your module is listed in the vtigercrm admin console. Settings &amp;gt; Module Manager page under the custom module. Here we can disable/enable and export your module for future use.

if you click on the export buttom, a Zip file will be downloaded as an installtion file. and we are reuse it in other vtiger applications.
&lt;/div&gt;</description><link>http://phpqa.blogspot.com/2012/02/creating-custom-module-in-vtigercrm.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-2566723819161419242</guid><pubDate>Fri, 06 Jan 2012 10:38:00 +0000</pubDate><atom:updated>2012-01-06T10:38:51.557+00:00</atom:updated><title>Can we compare equality of two floats in php ?</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Can we compare equality of two floats in php ? 
&lt;br /&gt;
&lt;br /&gt;
The answer is NO.  Its not encouraged in php programming. The reason is, its related to system confugurations. We can not trust these values, it may vary in different systems. 

Consider this example 
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
if( 0.111 + 0.222 == 0.333 ){
 echo 'a and b are same';
}
else {
 echo 'a and b are not same';
} 
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Here the value 0.333 is A literal but a float(calculated sum) using to compare it. So it may result some variations in the result. some times it will show the 'true' part, sometime it will show the 'false' part.
&lt;br /&gt;
You can see its more explantions on php.net
&lt;br /&gt;
here are the links&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://php.net/manual/en/language.operators.comparison.php%C2%A0"&gt;http://php.net/manual/en/language.operators.comparison.php&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://in.php.net/float"&gt;http://in.php.net/float&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;To overcome this, we can use the precition checking 
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
  function floatCheck($x,$y,$precision=0.0000001) 
    { 
        return ($x+$precision &amp;gt;= $y) &amp;amp;&amp;amp; ($x-$precision &amp;lt;= $y); 
    }

floatCheck(1.0002541,1.0002540,$precision=0.0000002);

&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</description><link>http://phpqa.blogspot.com/2012/01/can-we-compare-equality-of-two-floats.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-151788849929469224</guid><pubDate>Mon, 10 Oct 2011 13:56:00 +0000</pubDate><atom:updated>2011-10-11T15:26:40.262+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">apache</category><category domain="http://www.blogger.com/atom/ns#">htacess</category><category domain="http://www.blogger.com/atom/ns#">php</category><category domain="http://www.blogger.com/atom/ns#">php tips</category><title>How to add or remove WWW on URLs using htaccess.</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
How to add or remove WWW on URLs using htaccess. 

Adding www to your site url using .htaccess

&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yoursite.in$ 
RewriteRule (.*) http\:\/\/www\.yoursite\.in\/$1 [R=301]
&lt;/code&gt;
&lt;/pre&gt;
Removing www from your site url using .htaccess

&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
RewriteCond %{HTTP_HOST} ^yoursite\.in$ [OR]
RewriteCond %{HTTP_HOST} ^www\.yoursite\.in$ [NC]
RewriteRule ^/?$ "http\:\/\/yoursite\.in\/" [R=301,L]
&lt;/code&gt;
&lt;/pre&gt;
&lt;/div&gt;</description><link>http://phpqa.blogspot.com/2011/10/how-to-add-or-remove-www-on-urls-using.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-3053325679208666940</guid><pubDate>Sat, 01 Oct 2011 14:34:00 +0000</pubDate><atom:updated>2011-10-11T15:16:12.884+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">apache</category><category domain="http://www.blogger.com/atom/ns#">php</category><category domain="http://www.blogger.com/atom/ns#">php tips</category><title>Compressing HTML, CSS and Javascript using Apache</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Compressing HTML, CSS, Javascript using Apache

There are two methods to available in apache to handle compression of webpage contents. They are mod_gzip and mod_deflate . Usually deflate comes pre-installed on servers. We can install both in our apache server. before we install, lets check is it availble in your server,
&lt;br /&gt;
&lt;br /&gt;
In order to check whether these apache directives are installed or not, we can create a test php file with calling function the phpinfo() function. From that we can see "Loaded Modules" setting in the "apache2handler" header.
&lt;br /&gt;
&lt;br /&gt;
From that we can see whether its installed or not. in the case of deflate, we can see "mod_deflate" under that section.
&lt;br /&gt;
&lt;br /&gt;
Install mod_deflate in your server
&lt;br /&gt;
&lt;br /&gt;
a2enmod deflate 
&lt;br /&gt;
&lt;br /&gt;
the restart your apache with the following command
&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/apache2 restart
&lt;br /&gt;
&lt;br /&gt;
We can enable this feature using .httacess file in the root directory

&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
## Apache2 deflate support if available
##
## Important note: mod_headers is required for correct functioning across proxies.
##
&lt;ifmodule mod_deflate.c=""&gt;
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.[0678] no-gzip
BrowserMatch \bMSIE !no-gzip

&lt;ifmodule mod_headers.c=""&gt; 
Header append Vary User-Agent env=!dont-vary
&lt;/ifmodule&gt; 
 
# The following is to disable compression for actions. The reason being is that these
# may offer direct downloads which (since the initial request comes in as text/html and headers
# get changed in the script) get double compressed and become unusable when downloaded by IE.
SetEnvIfNoCase Request_URI action\/* no-gzip dont-vary
SetEnvIfNoCase Request_URI actions\/* no-gzip dont-vary
 
&lt;/ifmodule&gt;
&lt;/code&gt;
&lt;/pre&gt;
This is a simple version for the usage of mod_deflate.c in .httacces

&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
&lt;ifmodule mod_deflate.c=""&gt;
 AddOutputFilterByType DEFLATE application/x-javascript text/css text/html text/xml
&lt;/ifmodule&gt;
&lt;/code&gt;
&lt;/pre&gt;
The another option is mod_gzip, it is usually 4 -6 times faster than deflate. But its needs too much server load compared to deflate. 
So its advised to use mod_gzip on low-traffic sites and in large traffic sites, its better to use deflate.

The settings for mod_zip is following. its can be given in a .htaccess file.

&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
# Turn on mod_gzip if available
&lt;ifmodule mod_gzip.c=""&gt;
    mod_gzip_on yes
    mod_gzip_dechunk yes
    mod_gzip_keep_workfiles No
    mod_gzip_minimum_file_size 1000
    mod_gzip_maximum_file_size 1000000
    mod_gzip_maximum_inmem_size 1000000
    mod_gzip_item_include mime ^text/.* 
    mod_gzip_item_include mime ^application/javascript$
    mod_gzip_item_include mime ^application/x-javascript$
    # Exclude old browsers and images since IE has trouble with this
    mod_gzip_item_exclude reqheader "User-Agent: .*Mozilla/4\..*\["
    mod_gzip_item_exclude mime ^image/.*
&lt;/ifmodule&gt;
&lt;/code&gt;
&lt;/pre&gt;
&lt;/div&gt;</description><link>http://phpqa.blogspot.com/2011/10/compressing-html-css-and-javascript.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-6298915598586052781</guid><pubDate>Fri, 23 Sep 2011 16:46:00 +0000</pubDate><atom:updated>2011-09-23T18:00:55.952+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Mysql</category><title>Mysql optimization by configuring the query cache</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;b&gt;Mysql optimization by configuring the query cache&lt;/b&gt;

&lt;br /&gt;
In Ubuntu (debian) the query cache settings can be changed in the following file 

/etc/mysql/my.cnf&lt;br /&gt;
&amp;nbsp;Use the following command to edit the file
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;&amp;nbsp;nano /etc/mysql/my.cnf or vi /etc/mysql/my.cnf &lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
In this file you can find following settings.
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;#  Query Cache Configuration
#   
query_cache_limit       = 1M
query_cache_size        = 16M
#&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Query Cache options

SQL_CACHE 
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;SELECT SQL_CACHE id, name FROM students;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
SQL_NO_CACHE
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt; SELECT SQL_NO_CACHE id, name FROM students; &lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
We can check whether cache enabled in mysql database
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt; mysql&amp;gt; SHOW VARIABLES LIKE 'have_query_cache'; &lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
We can set Query_cache by queries
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;mysql&amp;gt;SET GLOBAL query_cache_size = 41984; &lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
If "query_cache_size " has value '0', then query cache is disabled, in the mysql environment. Also need to take care about the setting the query_cache_size with huge value. that will affect the system.

For more information about the query caching you can visit &lt;a href="http://dev.mysql.com/doc/refman/5.1/en/query-cache.html"&gt;http://dev.mysql.com/doc/refman/5.1/en/query-cache.html&lt;/a&gt;

&lt;/div&gt;
</description><link>http://phpqa.blogspot.com/2011/09/mysql-optimization-by-configuring-query.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-4710515567788988974</guid><pubDate>Wed, 14 Sep 2011 16:00:00 +0000</pubDate><atom:updated>2011-09-15T13:12:45.622+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Mysql</category><category domain="http://www.blogger.com/atom/ns#">php</category><title>Stored Procedures in Mysql</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Lets have a look on How to use the Stored Procedures in Mysql. We can use these stored procedures in PHP. The following example shows how to use mysql stored functions in PHP scripts.

Defining a stored function

&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
DELIMITER $$

DROP PROCEDURE IF EXISTS `tester`.`GetAllProducts`$$
CREATE PROCEDURE `tester`.GetAllProducts(IN t INT,IN age INT)
 BEGIN
 UPDATE students SET age = age WHERE id = t;
 INSERT INTO students (name,age,sex) VALUES ('Jayan',35,'M');
 END $$
DELIMITER ;
&lt;/code&gt;
&lt;/pre&gt;
Calling a stored function from PHP

&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
$res = mysql_query('call GetAllProducts(2,30)');

if ($res === FALSE) {
    die(mysql_error());
} else {
    echo "@";
    print_r($res);
}
&lt;/code&gt;
&lt;/pre&gt;
&lt;/div&gt;
</description><link>http://phpqa.blogspot.com/2011/09/lets-have-look-on-how-to-use-stored.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-9176238266367221808</guid><pubDate>Wed, 24 Aug 2011 12:54:00 +0000</pubDate><atom:updated>2011-08-24T14:01:40.163+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Mysql</category><category domain="http://www.blogger.com/atom/ns#">Mysql Questions</category><category domain="http://www.blogger.com/atom/ns#">stored functions</category><category domain="http://www.blogger.com/atom/ns#">stored procedures</category><title>Mysql Stored Functions And PHP</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Let us have a look on How to use the Stored Functions in Mysql. Here I am trying to show you how to use mysql stored functions in PHP scrips.

Hope you all know, what is Mysql Stored Functions. Its like  normal mysql functions, its written by the user. It will return results as a normal mysql functions. It can be called in normal sql statements.

Defining a stored function

&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
DELIMITER $$

DROP FUNCTION IF EXISTS `tester`.`sf_test`$$
CREATE FUNCTION `tester`.`sf_test` ()
RETURNS INT
READS SQL DATA
BEGIN
    DECLARE tot_count INT;
    select count(*) INTO tot_count from students;
    RETURN tot_count;
END$$

DELIMITER ;
&lt;/code&gt;
&lt;/pre&gt;
Calling a stored function from PHP

&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
$res = mysql_query('select sf_test()');

if ($res === FALSE) {
    die(mysql_error());
} else {
    echo "@";
    print_r($res);
}
&lt;/code&gt;
&lt;/pre&gt;
&lt;/div&gt;
</description><link>http://phpqa.blogspot.com/2011/08/let-have-have-look-how-to-use-stored.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-1192402595960166273</guid><pubDate>Thu, 19 May 2011 14:30:00 +0000</pubDate><atom:updated>2011-05-20T12:38:04.682+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Mysql</category><category domain="http://www.blogger.com/atom/ns#">Mysql Questions</category><category domain="http://www.blogger.com/atom/ns#">query helper</category><title>How to find out the CREATE TABLE statement of a selected table.</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div&gt;How to find out the CREATE TABLE statement of a selected table.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The 'SHOW CREATE TABLE' command will show the CREATE TABLE statement of a selected table. It will be very helpful for the&amp;nbsp;database backup actions.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;pre&gt;&lt;code&gt;SHOW CREATE TABLE `tablename`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;It will return two colomns one is its table name and other is the 'CREATE TABLE' statement.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;CREATE TABLE `tablename` (&lt;/div&gt;&lt;div&gt;&amp;nbsp;`id` int(10) NOT NULL,&lt;/div&gt;&lt;div&gt;&amp;nbsp;`title` varchar(256) NOT NULL&lt;/div&gt;&lt;div&gt;) ENGINE=MyISAM DEFAULT CHARSET=latin1&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Hope this will helpful for someone !&amp;nbsp;&lt;/div&gt;&lt;span style="color: #989898; font-family: 'Times New Roman'; font-size: x-large;"&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt; &lt;/div&gt;</description><link>http://phpqa.blogspot.com/2011/05/how-to-find-out-create-table-statement.html</link><author>noreply@blogger.com (jj)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-1021042703866434109</guid><pubDate>Tue, 19 Apr 2011 09:45:00 +0000</pubDate><atom:updated>2011-05-20T13:06:13.362+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Mysql</category><category domain="http://www.blogger.com/atom/ns#">Mysql Questions</category><title>How to find out the Mysql storage engine type of a table.</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div&gt;How to find out the Mysql storage engine type of a table.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The following queries will show the engine type of a table&lt;/div&gt;&lt;div&gt;&lt;pre&gt;&lt;code&gt;
SHOW
TABLE STATUS
WHERE
name= 'tablename';&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The Following query will also help you to find out the storage engine.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Each Mysql table's informations are stored in the 'INFORMATION_SCHEMA' table.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The following query will show the storage engine's of the given databse table.&lt;/div&gt;&lt;div&gt;&lt;pre&gt;&lt;code&gt;
SELECT 
TABLE_NAME,ENGINE 
FROM information_schema.TABLES
WHERE 
TABLE_SCHEMA = 'dbname'&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;To show particular table's mysql engine type.&lt;/div&gt;&lt;div&gt;&lt;pre&gt;&lt;code&gt;
SELECT TABLE_NAME,
ENGINE FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'dbname'
AND TABLE_NAME = 'tablename'&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Hope this will helpful for you all.&lt;/div&gt;&lt;/div&gt;</description><link>http://phpqa.blogspot.com/2011/05/how-to-find-out-mysql-storage-engine.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-5070146910040484848</guid><pubDate>Wed, 02 Mar 2011 14:18:00 +0000</pubDate><atom:updated>2011-03-02T14:20:13.617+00:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">codeigniter</category><category domain="http://www.blogger.com/atom/ns#">php</category><category domain="http://www.blogger.com/atom/ns#">php functions</category><title>Checking for a valid date for date of birth and age verification - Codeigniter</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Its a callback function for codeigniter Form validation class. It will check, whether the input date is a valid date, and it will also check whether the user is above a particular age limit. Here its 13 years.&lt;br /&gt;
&lt;br /&gt;
You can use this function in codeigniter as given below&lt;br /&gt;
&lt;br /&gt;
load form validation class for codeigniter into your controller functions&lt;br /&gt;
&lt;br /&gt;
$this-&amp;gt;load-&amp;gt;library('form_validation');&lt;br /&gt;
&lt;br /&gt;
Set the rules for date of birth field&lt;br /&gt;
&lt;br /&gt;
$config = array(&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array(&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'field'&amp;nbsp;&amp;nbsp; =&amp;gt; 'dob',&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'label'&amp;nbsp;&amp;nbsp; =&amp;gt; 'date of birth',&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'rules'&amp;nbsp;&amp;nbsp; =&amp;gt; 'trim|required|callback_dob_valid'&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ),&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;br /&gt;
&lt;br /&gt;
if you need you can add additional rules &lt;br /&gt;
Set the Rule for your form&lt;br /&gt;
&lt;br /&gt;
$this-&amp;gt;form_validation-&amp;gt;set_rules($config); &lt;br /&gt;
&lt;br /&gt;
then run the form against these rules&lt;br /&gt;
&lt;br /&gt;
if ($this-&amp;gt;form_validation-&amp;gt;run() == FALSE)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // reload the view &lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // success action&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
&amp;nbsp;* Date of birth&lt;br /&gt;
&amp;nbsp;* Checking for a valid date for date of birth and age verification&lt;br /&gt;
&amp;nbsp;* &lt;br /&gt;
&amp;nbsp;* @author http://phpqa.in&lt;br /&gt;
&amp;nbsp;* @since &lt;br /&gt;
&amp;nbsp;* @copyright GPL&amp;nbsp; &lt;br /&gt;
&amp;nbsp;*/&lt;br /&gt;
function dob_valid($str)&lt;br /&gt;
{&lt;br /&gt;
if($str)&lt;br /&gt;
{&lt;br /&gt;
//match the format of the date dd-mm-yyyy&lt;br /&gt;
&amp;nbsp;// for yyyy-mm-dd&amp;nbsp; use "/^([0-9]{4})-([0-9]{2})-([0-9]{4})$/&lt;br /&gt;
&amp;nbsp;if (preg_match ("/^([0-9]{2})-([0-9]{2})-([0-9]{4})$/", $str, $parts))&lt;br /&gt;
&amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; //check weather the date is valid of not&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp; $day&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = $parts[1];&lt;br /&gt;
&amp;nbsp;&amp;nbsp; $month = $parts[2];&lt;br /&gt;
&amp;nbsp;&amp;nbsp; $year&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = $parts[3];&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp; /* &lt;br /&gt;
&amp;nbsp;&amp;nbsp; // for yyyy-mm-dd&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp; $day&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = $parts[3];&lt;br /&gt;
&amp;nbsp;&amp;nbsp; $month = $parts[2];&lt;br /&gt;
&amp;nbsp;&amp;nbsp; $year&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = $parts[1];&lt;br /&gt;
&amp;nbsp;&amp;nbsp; */&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp; // checking 4 valid date&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp; if(!checkdate($month,$day,$year))&lt;br /&gt;
&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
$this-&amp;gt;form_validation-&amp;gt;set_message('dob_valid', '%s is not a valid date, use dd-mm-yyyy format');&lt;br /&gt;
return false;&lt;br /&gt;
} &lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
//check for future date&lt;br /&gt;
$dob = $year.'-'.$month.'-'.$day;&lt;br /&gt;
if($dob &amp;lt; date("Y-m-d"))&lt;br /&gt;
{&lt;br /&gt;
// age verification using DOB&lt;br /&gt;
$dob_time = mktime(0, 0, 0, $month,$day,$year);&lt;br /&gt;
$age_req = strtotime('+13 years', $dob_time);&lt;br /&gt;
if(time() &amp;lt; $age_req)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; $this-&amp;gt;form_validation-&amp;gt;set_message('dob_valid', 'You must be atleast 13 years old');&lt;br /&gt;
&amp;nbsp;&amp;nbsp; return false;&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; return true;&lt;br /&gt;
}&lt;br /&gt;
return true;&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
$this-&amp;gt;form_validation-&amp;gt;set_message('dob_valid', '%s should be a past date');&lt;br /&gt;
return false;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&amp;nbsp;}&lt;br /&gt;
&amp;nbsp;else&lt;br /&gt;
&amp;nbsp;{&lt;br /&gt;
&amp;nbsp; $this-&amp;gt;form_validation-&amp;gt;set_message('dob_valid', '%s is not a valid date, use dd-mm-yyyy format');&lt;br /&gt;
&amp;nbsp; return false;&lt;br /&gt;
&amp;nbsp;}&lt;br /&gt;
}&lt;br /&gt;
return false;&lt;br /&gt;
}&amp;nbsp; &lt;br /&gt;
By removing the "$this-&amp;gt;form_validation-&amp;gt;set_message()" function from the above function we can use the above function in any php scripts&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;/div&gt;</description><link>http://phpqa.blogspot.com/2011/03/checking-for-valid-date-for-date-of.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-6360956936452636243</guid><pubDate>Fri, 18 Feb 2011 11:47:00 +0000</pubDate><atom:updated>2011-02-18T12:01:59.262+00:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><category domain="http://www.blogger.com/atom/ns#">php functions</category><title>function to validate the a given credit card based on the card type and based on luhns algorithm</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: arial; font-size: x-small;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;function to validate the a given credit card based on the card type and based on luhns algorithm &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; /**&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; * function to validate a given credit card based on the card type and based &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;on luhns algorithm&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; *&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; * @param $c_number credit card number&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; * @param $c_type credit card type&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; * @return boolean. true or false.&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; *&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; */&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function validateCreditCard($c_number,$c_type='')&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;$cc_num = $number;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;if($c_type == "American")&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;$denum = "American Express";&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;elseif($c_type == "Dinners")&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;$denum = "Diner's Club";&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;elseif($c_type == "Discover")&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;$denum = "Discover";&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;elseif($c_type == "Master")&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;$denum = "Master Card";&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;elseif($c_type == "Visa")&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;$denum = "Visa";&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;else&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;       &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;// checking card types and its length based on card type&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;if($type == "American")&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;$pattern = "/^([34|37]{2})([0-9]{13})$/"; //American Express&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;if (preg_match($pattern,$cc_num))&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;$verified = true;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;} else&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;$verified = false;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;elseif($type == "Dinners")&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;$pattern = "/^([30|36|38]{2})([0-9]{12})$/"; //Diner's Club&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;if (preg_match($pattern,$cc_num))&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;$verified = true;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;} else {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;$verified = false;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;elseif($type == "Discover")&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;$pattern = "/^([6011]{4})([0-9]{12})$/"; //Discover Card&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;if (preg_match($pattern,$cc_num))&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;$verified = true;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;} else {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;$verified = false;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;elseif($type == "Master")&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;$pattern = "/^([51|52|53|54|55]{2})([0-9]{14})$/"; //Mastercard&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;if (preg_match($pattern,$cc_num))&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;$verified = true;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;} else&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;$verified = false;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;}&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;elseif($type == "Visa")&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;$pattern = "/^([4]{1})([0-9]{12,15})$/"; //Visa&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;if (preg_match($pattern,$cc_num))&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;$verified = true;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;}&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;else&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;$verified = false;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;if($verified == false)&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;{&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;return false;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;else&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;{&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;// checking the card number with luhns algorithm&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;$stack = 0;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;$number = str_split(strrev($number), 1);&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;if(array_sum($number) == 0)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;return false;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;}&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;foreach ($number as $key =&amp;gt; $value)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;if ($key % 2 != 0)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;{&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;     &lt;/span&gt;$value = array_sum(str_split($value * 2, 1));&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;$stack += $value;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;}&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;if($stack%10 == 0)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;return true;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;return false;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;blockquote&gt;Sample code to use the function.&lt;/blockquote&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;if(validateCreditCard("340000000000009","American"))&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;echo "Yeah Its a valid credit card number";&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;else&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;echo "Oops, Its not a valid credit card number";&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://phpqa.blogspot.com/2011/02/function-to-validate-a-given-credit.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-6841078025041422046</guid><pubDate>Tue, 12 Oct 2010 10:05:00 +0000</pubDate><atom:updated>2010-10-12T11:07:55.780+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">packaging problem</category><category domain="http://www.blogger.com/atom/ns#">php</category><title>solving the packaging problem in PHP</title><description>When, I was developing a shipping software based on Fedex ans UPS APIs, I got an issue with packagaging. It was, the packing the products in an optimised way. there are few methods to solve this issues in mathematics. Here's a program which can be used to solve the packaging problem.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; // setting up Max value for each contatiner&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;DEFINE('MAX_VALUE',40);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; // &amp;nbsp; different set of array values for testing&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;//$input = array(18,13,33,7,26,39,16,5);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;//$input = array(15,28,19,21,4,36,12,15);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;$input = array(1,2,3,4,5,30,6,7,8,9,10,1,2,3,4,5,30,6,7,8,9,10);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;//$input = array(15,15,15,15,15,10,10,25);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;$expected_containers = ceil(array_sum($input)/MAX_VALUE);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;$no_of_items = count($input);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;rsort($input);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;for($i = 0; $i &amp;lt; $no_of_items; $i++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(isset($input[$i]))&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$remainder = MAX_VALUE - $input[$i];&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for($j = $i + 1; $j &amp;lt;= $no_of_items; $j++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(isset($input[$j]) &amp;amp;&amp;amp; $input[$j] &amp;lt;= $remainder)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(!isset($container[$i]))&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$container[$i] = array($input[$i],$input[$j]);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;array_push($container[$i],$input[$j]);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$remainder = $remainder - $input[$j];&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;unset($input[$j]); &lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(!isset($container[$i]))&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$container[$i] = array($input[$i]);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;echo "Expected containers ".$expected_containers."&lt;br /&gt;
";&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;echo "Actual containers ".count($container)."&lt;br /&gt;
";&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;echo '&lt;br /&gt;
&lt;pre&gt;';

&amp;nbsp;&amp;nbsp; &amp;nbsp;print_r($container);

&amp;nbsp;&amp;nbsp; &amp;nbsp;foreach($container as $val)
&amp;nbsp;&amp;nbsp; {
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;$productsum = array_sum($val);
&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;echo &amp;nbsp;"
".$productsum;
&amp;nbsp;&amp;nbsp; }&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;

&amp;nbsp;&amp;nbsp; echo '&lt;/pre&gt;';&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
seems helpful someone, who is developing a shipping software.&lt;br /&gt;
&lt;br /&gt;
@credits Praveesh&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;</description><link>http://phpqa.blogspot.com/2010/10/solving-packaging-problem-in-php.html</link><author>noreply@blogger.com (jj)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-8060179374809911495</guid><pubDate>Fri, 10 Sep 2010 10:57:00 +0000</pubDate><atom:updated>2010-09-10T11:57:44.392+01:00</atom:updated><title>Handling the multiple checkboxes with Jquery for Check All, Uncheck All and get values from selected values V2</title><description>Handling the multiple checkboxes with jquery for Check All, Uncheck All&lt;br&gt;and get values from selected values. V2 For new versions of Jquery.&lt;p&gt;&lt;br&gt;include jquery&lt;p&gt;&amp;lt;script language=&amp;quot;JavaScript&amp;quot; src=&amp;quot;youserveraddres/js/jquery.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;p&gt;&lt;br&gt;your html&lt;p&gt;&amp;lt;input name=&amp;quot;phpqa[]&amp;quot; type=&amp;quot;checkbox&amp;quot; value=&amp;quot;1&amp;quot;&amp;gt;1&lt;br&gt;&amp;lt;input name=&amp;quot;phpqa[]&amp;quot; type=&amp;quot;checkbox&amp;quot; value=&amp;quot;2&amp;quot;&amp;gt;2&lt;br&gt;&amp;lt;input name=&amp;quot;phpqa[]&amp;quot; type=&amp;quot;checkbox&amp;quot; value=&amp;quot;3&amp;quot;&amp;gt;3&lt;br&gt;&amp;lt;input name=&amp;quot;phpqa[]&amp;quot; type=&amp;quot;checkbox&amp;quot; value=&amp;quot;4&amp;quot;&amp;gt;4&lt;br&gt;&amp;lt;input name=&amp;quot;phpqa[]&amp;quot; type=&amp;quot;checkbox&amp;quot; value=&amp;quot;5&amp;quot;&amp;gt;5&lt;br&gt;&amp;lt;input name=&amp;quot;phpqa[]&amp;quot; type=&amp;quot;checkbox&amp;quot; value=&amp;quot;6&amp;quot;&amp;gt;6&lt;br&gt;&amp;lt;input name=&amp;quot;phpqa[]&amp;quot; type=&amp;quot;checkbox&amp;quot; value=&amp;quot;7&amp;quot;&amp;gt;7&lt;br&gt;&amp;lt;input name=&amp;quot;phpqa[]&amp;quot; type=&amp;quot;checkbox&amp;quot; value=&amp;quot;8&amp;quot;&amp;gt;8&lt;p&gt;&amp;lt;a href=&amp;quot;javascript:void();&amp;quot; onclick=&amp;quot;markAll()&amp;quot;&amp;gt;Check All&amp;lt;/a&amp;gt;&lt;br&gt;&amp;lt;a href=&amp;quot;javascript:void();&amp;quot; onclick=&amp;quot;unMarkAll()&amp;quot;&amp;gt;Uncheck All&amp;lt;/a&amp;gt;&lt;br&gt;&amp;lt;a href=&amp;quot;javascript:void();&amp;quot; onclick=&amp;quot;getSelectedVals()&amp;quot;&amp;gt;Get Checked Values&amp;lt;/a&amp;gt;&lt;p&gt;&lt;br&gt;// function for mark all / check all&lt;p&gt;function markAll(){&lt;br&gt;$(&amp;quot;input[name=&amp;#39;phpqa[]&amp;#39;]&amp;quot;).each(function() {&lt;br&gt;this.checked = true;&lt;br&gt;});&lt;br&gt;}&lt;p&gt;&lt;br&gt;// function for uncheck all&lt;p&gt;function unMarkAll(){&lt;br&gt;$(&amp;quot;input[name=&amp;#39;phpqa[]&amp;#39;]&amp;quot;).each(function() {&lt;br&gt;this.checked = false;&lt;br&gt;});&lt;br&gt;}&lt;p&gt;&lt;br&gt;//fetching selected values / checked values&lt;p&gt;function getSelectedVals(){&lt;br&gt;$(&amp;quot;input[name=&amp;#39;phpqa[]&amp;#39;]&amp;quot;).each(function() {&lt;br&gt;if ($(this).attr(&amp;#39;checked&amp;#39;))&lt;br&gt;{&lt;br&gt;alert($(this).val());&lt;br&gt;}&lt;br&gt;});&lt;br&gt;}</description><link>http://phpqa.blogspot.com/2010/09/handling-multiple-checkboxes-with.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-2314050850725769395</guid><pubDate>Mon, 16 Nov 2009 06:12:00 +0000</pubDate><atom:updated>2009-11-16T06:15:57.709+00:00</atom:updated><title>How to set up .htpasswd in a site ?</title><description>&lt;div class="gmail_quote"&gt;How to set up .htpasswd in a site ?&lt;br /&gt;
&lt;br /&gt;
Step 1 : create file &lt;b&gt;.htpasswd&lt;/b&gt; and put out side our root folder but inside www for safety.&lt;br /&gt;
&lt;br /&gt;
Step 2 : open the file &lt;b&gt;.htpasswd&lt;/b&gt; and add like username:password -&amp;gt; then save and close. So now file contains &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; username:password&lt;br /&gt;
&lt;br /&gt;
Step 3 : Add the following in .htaccess file&lt;br /&gt;
&lt;br /&gt;
AuthName "Restricted Area" &lt;br /&gt;
AuthType Basic &lt;br /&gt;
AuthUserFile D:/wamp/www/.htpasswd # full path to .htpasswd file&lt;br /&gt;
AuthGroupFile /dev/null &lt;br /&gt;
require valid-user&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
Now open you site &lt;a href="http://mysite.com/" target="_blank"&gt;http://mysite.com&lt;/a&gt;&lt;br /&gt;
It will ask username and password to display.&lt;br /&gt;
&lt;br /&gt;
Use this functionality in all admin side. It will block all hackers.&lt;br /&gt;
&lt;br /&gt;
Posted by : Shijith Nambiar &lt;br /&gt;
&lt;/div&gt;</description><link>http://phpqa.blogspot.com/2009/11/how-to-set-up-htpasswd-in-site.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-4553180061248771656</guid><pubDate>Fri, 11 Sep 2009 11:25:00 +0000</pubDate><atom:updated>2009-09-11T12:27:40.039+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">web technics</category><title>Some htaccess tips</title><description>&lt;em&gt;Redirecting a domain into an another directory of same level&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;Consider there is a domain called mydomain.com, which curretly pointed to a directory named 'folder1' in the home directory(public_html). Now, I just want to redirect this domain to an another directory, which is in the same home folder(public_html named 'folder2'&lt;br /&gt;&lt;br /&gt;In this case we could use the following htaccess code, just remember that you have included the 'RewriteEngine On' statement at the beginning of the htaccess file&lt;br /&gt;&lt;br /&gt;RewriteCond %{HTTP_HOST} ^mydomain\.com$ [OR]&lt;br /&gt;RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$&lt;br /&gt;RewriteCond %{REQUEST_URI} !^/folder2/&lt;br /&gt;RewriteRule (.*) /folder2/$1&lt;br /&gt;&lt;br /&gt;Now the when type mydomain.com/folder2 it will redirect the folder named 'folder2' in which the directory level the folder 'folder1' is. Not to the subfolder of folder1.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Another case of usage of htaccess redirect.&lt;br /&gt;&lt;br /&gt;For setting an HTML splash page for your domain.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;if you want to redirect all the traffic to the domain mydomain.com/ to a new folder named /anothersub, but you want to keep the other existing subfolders of mydomain.com/ working as they act&lt;br /&gt;&lt;br /&gt;RewriteCond %{HTTP_HOST} ^mydomain\.com$ [OR]&lt;br /&gt;RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$&lt;br /&gt;RewriteCond %{REQUEST_URI} ^/$&lt;br /&gt;RewriteRule (.*) /anothersub/index.html&lt;br /&gt;&lt;br /&gt;In this case the traffic to  mydomain.com will go to mydomain.com/anothersub/index.html instead of mydomain.com/index.html.&lt;br /&gt;but the traffic to mydomain.com/subfolder1 , mydomain.com/subfolder2, blah blah .. will go to corresponding pages as usual.</description><link>http://phpqa.blogspot.com/2009/09/some-htaccess-tips_11.html</link><author>noreply@blogger.com (jj)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-1435099440434492822</guid><pubDate>Wed, 19 Aug 2009 08:50:00 +0000</pubDate><atom:updated>2009-08-19T10:29:11.895+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">linux</category><title>Adding cronjobs in Linux using SSH</title><description>&lt;span style="font-weight: bold;"&gt;Adding cron tasks in Linux using SSH&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;in most hosting platforms we have the control panel console to add cron tabs. But in the case of our local linux machine, or server's which does not have control panel, we could use the following&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;adding the commands in the crontab&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Login in the console as super user&lt;br /&gt;&lt;br /&gt;Use the following command " sudo crontab -e " to open the crontab file.&lt;br /&gt;  Some times you will get a message to select the editor to open the file. select the desired editor. the crontab file will open and it contains the syntax for the crontab command. its looks like " # m h  dom mon dow command "&lt;br /&gt;&lt;br /&gt;       m      -&gt; minute&lt;br /&gt;       h         -&gt; hour&lt;br /&gt;       dom  -&gt; date of month&lt;br /&gt;           mon  -&gt; Month&lt;br /&gt;       dow  -&gt; day of week&lt;br /&gt;&lt;br /&gt;for setting cron for every minute use the following code&lt;br /&gt;&lt;br /&gt;              * * * * * yourcommand&lt;br /&gt;&lt;br /&gt;for each five minutes&lt;br /&gt;&lt;br /&gt;            */5 * * * * yourcommand&lt;br /&gt;&lt;br /&gt;For hourly cron&lt;br /&gt;&lt;br /&gt;         0 * * * * yourcommand&lt;br /&gt;&lt;br /&gt;For daily cron&lt;br /&gt;&lt;br /&gt;         0 0 * * * yourcommand&lt;br /&gt;&lt;br /&gt;for yearly&lt;br /&gt; &lt;br /&gt;             0 0 1 1 * yourcommand&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;we could also run the cron in particular minute ,hour etc.&lt;br /&gt;&lt;br /&gt;      15,45 * * * yourcommand&lt;br /&gt;&lt;br /&gt;the cron will run each 15 and 45 min of every hour&lt;br /&gt;&lt;br /&gt;           0 12,24 * * yourcommand&lt;br /&gt;&lt;br /&gt;the cron will run each 12 and 24 every hour&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;where the value of * holds value "Every".&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;After setting the cronjob save the cron tab file.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;For testing these cronsettings please follow following steps..&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;create the php script  and save as mycron.php&lt;br /&gt;&lt;br /&gt;&lt;wbr&gt;root","root");&lt;br /&gt;mysql_select_db("crontest");&lt;br /&gt;$date = date("Y-m-d H:i:s");&lt;br /&gt;mysql_query("INSERT INTO `test`(`timer`) VALUES ('$date')");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;create corresponding database and table&lt;br /&gt;&lt;br /&gt;CREATE TABLE IF NOT EXISTS `test` (&lt;br /&gt;`id` int(11) NOT NULL auto_increment,&lt;br /&gt;`timer` datetime NOT NULL default '0000-00-00 00:00:00',&lt;br /&gt;PRIMARY KEY  (`id`)&lt;br /&gt;) ENGINE=MyISAM&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;open crontab file add following command&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;*/5 * * * * php /pathto/mycron.php&lt;br /&gt;&lt;br /&gt;and save the file and check back the mysql table for inserted values.&lt;br /&gt;&lt;br /&gt;I hope this post will help you know details about adding cron job without the control panel or plesk console in your server or in the local machine</description><link>http://phpqa.blogspot.com/2009/08/adding-cron-tasks-in-linux-using-ssh.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-4070226119215213266</guid><pubDate>Tue, 18 Aug 2009 16:17:00 +0000</pubDate><atom:updated>2009-08-19T10:14:13.120+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">linux</category><category domain="http://www.blogger.com/atom/ns#">php</category><title>Running php script on command line &amp; installing php5-cli library in  phpserver</title><description>&lt;b&gt;Running php script on command line &amp;amp; installing php5-cli library in phpserver&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;To run php in command line, you need to not only PHP, but also the PHP5-cli library in your php server. The PHP5-cli stands for command-line interpreter for the PHP5 scripting language. It is very useful when we need test our scripts from the shell. In some cases we need to install this library for running cronjobs on the server.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;how to install php5-cli. in linux machines.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;first login as super user : " su username "&lt;br /&gt;&lt;br /&gt;after login just use the following command "sudo apt-get install php5-cli "&lt;br /&gt;&lt;br /&gt;the php5-cli installation has completed&lt;br /&gt;&lt;br /&gt;just restart your apache server. For that we can use the following command&lt;br /&gt;&lt;br /&gt;&lt;b&gt;How  to restart a apache server on linux&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;sudo /etc/init.d/apache2 restart&lt;br /&gt;&lt;br /&gt;After the restart of your server, the php5-cli has been installed on your server. and just try to run a simple php script on your server.</description><link>http://phpqa.blogspot.com/2009/08/running-php-script-on-command-line.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-6296322373752664849</guid><pubDate>Thu, 13 Aug 2009 13:36:00 +0000</pubDate><atom:updated>2009-08-13T14:42:57.327+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><category domain="http://www.blogger.com/atom/ns#">php functions</category><title>Function to get the bytes in TB, GB, MB, KB from bytes</title><description>/*******************************/&lt;br /&gt;# function to get the byte format                #&lt;br /&gt;# @phpqa.blogspot.com                                #&lt;br /&gt;/*******************************/&lt;br /&gt;&lt;br /&gt;function getByteFormat($number,$&lt;wbr&gt;caption="small"){&lt;br /&gt;&lt;br /&gt;  $unit = "";&lt;br /&gt;  switch($number){&lt;br /&gt;&lt;br /&gt;      case($number &gt;= 1099511627776):&lt;br /&gt;&lt;br /&gt;          $number = round($number / 1099511627776, 1);&lt;br /&gt;          $unit = $caption == "small" ? "TB" : "Terabyte";&lt;br /&gt;          break; &lt;br /&gt;&lt;br /&gt;      case($number &gt;= 1073741824): &lt;br /&gt;&lt;br /&gt;          $number = round($number / 1073741824, 1);&lt;br /&gt;          $unit = $caption == "small" ? "GB" : "Gigabyte";         &lt;br /&gt;          break;&lt;br /&gt;&lt;br /&gt;      case($number &gt;= 1048576):&lt;br /&gt;&lt;br /&gt;          $number = round($number / 1048576, 1);&lt;br /&gt;          $unit = $caption == "small" ? "MB" : "Megabyte";&lt;br /&gt;          break;&lt;br /&gt;&lt;br /&gt;      case($num &gt;= 1024):&lt;br /&gt;&lt;br /&gt;          $number = round($number / 1024, 1);&lt;br /&gt;          $unit = $caption == "small" ? "KB" : "Kilobyte";&lt;br /&gt;          break;&lt;br /&gt;&lt;br /&gt;      default:     &lt;br /&gt;          $unit = $caption == "small" ? "B" : "Byte";&lt;br /&gt;          $number  = $number; &lt;br /&gt;          break;&lt;br /&gt;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  return number_format($number, 2).' '.$unit;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;# How to use   #&lt;br /&gt;&lt;br /&gt;echo getByteFormat(10995116277,"&lt;wbr&gt;big");&lt;br /&gt;echo getByteFormat(109951162799,"&lt;wbr&gt;small");&lt;br /&gt;echo getByteFormat(10995116261099);&lt;br /&gt;&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;please try this function and lemme give your feedback as comments</description><link>http://phpqa.blogspot.com/2009/08/function-to-get-bytes-in-tb-gb-mb-kb.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-6823982629050126688</guid><pubDate>Sun, 26 Jul 2009 18:53:00 +0000</pubDate><atom:updated>2009-07-27T17:31:07.484+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><category domain="http://www.blogger.com/atom/ns#">php functions</category><title>get current page url</title><description>&lt;p style="margin-bottom: 0.0001pt; line-height: normal; color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0.0001pt; line-height: normal; color: rgb(0, 0, 0);"&gt;&lt;span style="line-height: 115%;"&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:tahoma,sans-serif;"&gt;function get_url(){&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0.0001pt; line-height: normal; color: rgb(0, 0, 0);"&gt;&lt;span style="line-height: 115%;"&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:tahoma,sans-serif;"&gt;$server = empty( $_SERVER["HTTPS"] ) ? '' : ( $_SERVER["HTTPS"] == "on" ) ? "s" : "";&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;span style="color: rgb(0, 0, 0); white-space: nowrap;"&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:tahoma,sans-serif;"&gt;$root= &lt;/span&gt;&lt;/span&gt;&lt;span style="line-height: 115%;"&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:tahoma,sans-serif;"&gt; substr( strtolower ( $_&lt;wbr&gt;SERVER["SERVER_PROTOCOL"] ),  0,&lt;br /&gt;strpos( strtolower( $_SERVER["&lt;wbr&gt;SERVER_PROTOCOL"] ), "/") ) . $server;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:tahoma,sans-serif;"&gt;&lt;br /&gt;$root .= "://";&lt;br /&gt;if ($_SERVER["SERVER_PORT"] != "80") {&lt;br /&gt;$root.= $_SERVER["SERVER_NAME"]. " : " .$_&lt;wbr&gt;SERVER["SERVER_PORT"] . $_&lt;wbr&gt;SERVER["REQUEST_URI"];&lt;br /&gt;} else {&lt;br /&gt;$root.= $_SERVER["SERVER_NAME"] . $_&lt;wbr&gt;SERVER["REQUEST_URI"];&lt;br /&gt;}&lt;br /&gt;return $root;&lt;br /&gt;&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;</description><link>http://phpqa.blogspot.com/2009/07/get-current-page-url.html</link><author>noreply@blogger.com (jj)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-4104550839475036729</guid><pubDate>Sun, 26 Jul 2009 18:43:00 +0000</pubDate><atom:updated>2009-07-27T17:32:30.296+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><category domain="http://www.blogger.com/atom/ns#">php functions</category><title>creating  thumbs</title><description>&lt;p class="MsoNormal"&gt;The following function will help you to create  a thumbnail for an image.&lt;/p&gt;&lt;p class="MsoNormal"&gt;function get_thumb($img_filename, $maxwidth, $maxheight) {&lt;/p&gt;   &lt;p class="MsoNormal"&gt;$img_size = getimagesize($img_filename) ;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;if($img_size)&lt;span style=""&gt;   &lt;/span&gt;{&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;  &lt;/span&gt;$width = $img_size [0];&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;   &lt;/span&gt;$height = $img_size [1];&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt; &lt;/span&gt;&lt;span style=""&gt;  &lt;/span&gt;$thumb_height=$ height;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;   &lt;/span&gt;$thumb_width=$width;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;  &lt;span style=""&gt; &lt;/span&gt;if ($width &amp;gt; $maxwidth) {&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;     &lt;/span&gt;$thumb_width = $maxwidth;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;   &lt;/span&gt;&lt;span style=""&gt;  &lt;/span&gt;$thumb_height = floor($height * ($maxwidth / $width));&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;   &lt;/span&gt;}&lt;/p&gt;&lt;p class="MsoNormal"&gt;if ($thumb_height &amp;gt; $maxheight) {&lt;/p&gt;  &lt;p class="MsoNormal"&gt;$thumb_width = floor($thumb_width * ($maxheight / $thumb_height));&lt;/p&gt;&lt;p class="MsoNormal"&gt;$thumb_height = $maxheight;&lt;/p&gt;&lt;p class="MsoNormal"&gt;}&lt;/p&gt;  &lt;p class="MsoNormal"&gt;if ( (imgsizearray['mime']== 'image/jpeg')|| (imgsizearray['mime']== 'image/png')|| (imgsizearray['mime']== 'image/gif')) {&lt;/p&gt;  &lt;p class="MsoNormal"&gt; $type=explode('/', $imgsizearray['mime']);&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt; $thumb_image = imagecreatetruecolor($thumb_width, $thumb_height);&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt; &lt;/span&gt;$image ="imagecreatefrom" . $type[1] ($img_filename);&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;if($image){&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:100%;"&gt;/*&lt;/span&gt;&lt;span class="Apple-style-span" style=";font-family:verdana;font-size:100%;"  &gt;Copy and resize part of an image with resampling*/&lt;/span&gt;&lt;/p&gt;     &lt;p class="MsoNormal"&gt; imagecopyresampled($thumb_image, $image, 0,0,0,0,$thumb_width,$thumb_height,$width,$height);&lt;/p&gt;&lt;p class="MsoNormal"&gt;}&lt;span style=""&gt;                                                           &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;imagejpeg($thumb_image, null, 100);&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-family:&amp;quot;;font-size:9;"  &gt;  &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;      &lt;/span&gt;}&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;   }&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt; &lt;/span&gt;return false;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt; &lt;/span&gt;}&lt;/p&gt;  &lt;p class="MsoNormal"&gt;you can call the function like this . get_thumb ($file,100,100);&lt;br /&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;$img_filename is the uploaded file,and $maxwidth and $maxheight are the height and width specification for thumb&lt;/p&gt;</description><link>http://phpqa.blogspot.com/2009/07/create-thumbs.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-5546114136797101046</guid><pubDate>Sun, 26 Jul 2009 18:30:00 +0000</pubDate><atom:updated>2009-07-27T17:33:38.390+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><category domain="http://www.blogger.com/atom/ns#">php functions</category><title>securing a form with captcha</title><description>&lt;p class="MsoNormal"&gt;&lt;span class="apple-style-span"&gt;&lt;span style=";font-family:Arial;color:black;"  &gt;CAPTCHAs are used to prevent automated software from performing actions.CAPTCHAs have several applications for practical security, including&lt;span style=""&gt;  &lt;/span&gt;&lt;span style=""&gt;Preventing Comment Spam in Blogs,&lt;span class="MsoHyperlink"&gt;&lt;span style="color:black;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;Preventing Comment Spam in Blogs,&lt;/span&gt;&lt;/span&gt;CAPTCHAs also offer a plausible solution against email worms and spam.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;The following is &lt;span style=""&gt; &lt;/span&gt;an example for securing a form with captcha&lt;br /&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span&gt;  &lt;/span&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;main.php&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&amp;lt;?php&lt;/p&gt;&lt;p class="MsoNormal"&gt; require_once('functions.php');&lt;/p&gt;&lt;p class="MsoNormal"&gt;  If($_POST){&lt;/p&gt;&lt;p class="MsoNormal"&gt;If(validate_captcha()){&lt;/p&gt;&lt;p class="MsoNormal"&gt;echo&lt;span&gt;  &lt;/span&gt;"captcha okay";&lt;/p&gt; &lt;p class="MsoNormal"&gt;//do your&lt;span&gt;  &lt;/span&gt;actions here&lt;/p&gt;&lt;p class="MsoNormal"&gt;else{&lt;/p&gt;&lt;p class="MsoNormal"&gt;echo&lt;span&gt;  &lt;/span&gt;" captcha not okay";&lt;/p&gt;&lt;p class="MsoNormal"&gt;}&lt;/p&gt;&lt;p class="MsoNormal"&gt;}&lt;/p&gt;&lt;p class="MsoNormal"&gt; }else{&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span&gt;    &lt;/span&gt;mt_srand ((double)microtime()*1000000);&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span&gt;    &lt;/span&gt;$maxran = 1000000;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span&gt;    &lt;/span&gt;$random = mt_rand(0, $maxran);&lt;/p&gt; &lt;p class="MsoNormal"&gt; &lt;span&gt;  &lt;/span&gt;$html = "&amp;lt;html&amp;gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;lt;header&amp;gt;&amp;lt;title&amp;gt;form with captcha&amp;lt;/title&amp;gt;&amp;lt;/header&amp;gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;lt;body&amp;gt; &amp;lt;form&lt;span&gt;  &lt;/span&gt;name='frm' action='' method='post'&amp;gt;";&lt;/p&gt; &lt;p class="MsoNormal"&gt;$html.="name:&amp;lt;input&lt;span&gt;  &lt;/span&gt;type='text' name='txtname'&amp;gt;";&lt;/p&gt;&lt;p class="MsoNormal"&gt;$html.="password:&amp;lt;input&lt;span&gt;  &lt;/span&gt;type='password'&lt;span&gt;  &lt;/span&gt;name='txtpwd'&amp;gt;";&lt;/p&gt;&lt;p class="MsoNormal"&gt;  &lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span&gt;    &lt;/span&gt;$html .= "&amp;lt;div id=\"Registercode\"&amp;gt;&amp;lt;table&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;lt;img src='". create_captchaImg.php?ran=".$random." &amp;gt;&amp;lt;/td&amp;gt; ";&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span&gt;    &lt;/span&gt;$html .= "&amp;lt;td&amp;gt;&amp;lt;input type=\"text\" name=\"captchacode\" maxlength=\"10\" /&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;&amp;lt;/div&amp;gt;";&lt;/p&gt;&lt;p class="MsoNormal"&gt; &lt;span&gt; &lt;/span&gt;&lt;span&gt;   &lt;/span&gt;$html .= "&amp;lt;input&lt;span&gt;  &lt;/span&gt;type='hidden'&lt;span&gt;  &lt;/span&gt;name='randomcode'&lt;span&gt;  &lt;/span&gt;value='". $random."'&amp;gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;lt;input&lt;span&gt;  &lt;/span&gt;type='submit' name='submitbtn'&lt;span&gt;  &lt;/span&gt;value='submit' &amp;gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&amp;lt;/form&amp;gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;";&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span&gt;   &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span&gt;    &lt;/span&gt;echo $html;&lt;/p&gt;&lt;p class="MsoNormal"&gt;}&lt;/p&gt;&lt;p class="MsoNormal"&gt;?&amp;gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;functions.php&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&amp;lt;?php&lt;/p&gt;  &lt;p class="MsoNormal"&gt;/* function to generate captcha code */&lt;/p&gt;  &lt;p class="MsoNormal"&gt;function&lt;span style=""&gt;  &lt;/span&gt;generate_captcha($num) {&lt;/p&gt;  &lt;p class="MsoNormal"&gt;$timemd5=md5($num);&lt;/p&gt;  &lt;p class="MsoNormal"&gt;$date = date('F j');&lt;/p&gt;  &lt;p class="MsoNormal"&gt;$year=date('Y');&lt;/p&gt;  &lt;p class="MsoNormal"&gt;$temp=md5($num . $date.$year . $timemd5);&lt;/p&gt;  &lt;p class="MsoNormal"&gt;$capcode = hexdec($temp);&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt; &lt;/span&gt;$code = substr($capcode, 4, 6);&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt; &lt;/span&gt;return $code;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;}&lt;/p&gt;  &lt;p class="MsoNormal"&gt;/* function to validate captcha*/&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;    &lt;/span&gt;function&lt;span style=""&gt;  &lt;/span&gt;validate_captcha() {&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style=""&gt; &lt;/span&gt;$captchacode = $_POST['captchacode'];&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style=""&gt; &lt;/span&gt;$randomcode = $_POST['randomcode'];&lt;span style=""&gt;          &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;            &lt;/span&gt;$generated_code = generate_captcha($randomcode);&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;            &lt;/span&gt;$valid = false;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;            &lt;/span&gt;if ((trim($captchacode) != "") &amp;amp;&amp;amp; (strcmp($captchacode, $generated_code) == 0))&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;            &lt;/span&gt;$valid = true;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;            &lt;/span&gt;else&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;            &lt;/span&gt;$valid=false;&lt;/p&gt;  &lt;p class="MsoNormal"&gt; &lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;            &lt;/span&gt;return $valid;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;/p&gt;  &lt;p class="MsoNormal"&gt; &lt;/p&gt;  &lt;p class="MsoNormal"&gt;?&amp;gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt; &lt;/p&gt;  &lt;p class="MsoNormal"&gt; &lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;b&gt;create_captchaImg.php&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&amp;lt;?php &lt;/p&gt;  &lt;p class="MsoNormal"&gt;/* function to generate captcha image with the captcha code.choose some image as background */&lt;/p&gt;  &lt;p class="MsoNormal"&gt; &lt;/p&gt;  &lt;p class="MsoNormal"&gt;require_once('functions.php');&lt;/p&gt;  &lt;p class="MsoNormal"&gt;$ccode=$_REQUEST['ran'];&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;    &lt;/span&gt;$capcode = $ccode;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;    &lt;/span&gt;$code = generate_captcha($capcode);&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;    &lt;/span&gt;$image = ImageCreateFromJPEG("images/captchabg.jpeg");//give captcha&lt;span style=""&gt;  &lt;/span&gt;background image path&lt;/p&gt;  &lt;p class="MsoNormal"&gt; &lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;    &lt;/span&gt;$text_color = ImageColorAllocate($image, 80, 80, 80);&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;    &lt;/span&gt;Header("Content-type: image/jpeg");&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;    &lt;/span&gt;ImageString ($image, 5, 12, 2, $code, $text_color);&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;    &lt;/span&gt;ImageJPEG($image, '', 75);&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;    &lt;/span&gt;ImageDestroy($image);&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;      &lt;/span&gt;}&lt;/p&gt;  &lt;p class="MsoNormal"&gt;?&amp;gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt; &lt;/p&gt;  &lt;p class="MsoNormal"&gt; &lt;/p&gt;  &lt;p class="MsoNormal"&gt; &lt;/p&gt;  &lt;p class="MsoNormal"&gt; &lt;/p&gt;</description><link>http://phpqa.blogspot.com/2009/07/securing-form-with-captcha.html</link><author>noreply@blogger.com (jj)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-2752234068309394308</guid><pubDate>Thu, 23 Jul 2009 14:52:00 +0000</pubDate><atom:updated>2009-07-23T15:53:09.493+01:00</atom:updated><title>Function to find out last 12 months details from the current date</title><description>Function to find out last 12 months details from the current date&lt;p&gt;function getLast12MonthsDetails(){&lt;p&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; $month = date(&amp;#39;m&amp;#39;);&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; $year&amp;#160;   = date(&amp;#39;Y&amp;#39;);&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; $i         =  1;&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; $date   = a rray();&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; while($i&amp;lt;=12){&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &amp;#160; $timestamp                 = mktime(0,0,0,$month,1,$year);&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &amp;#160; $date[$i][&amp;#39;month&amp;#39;]&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;     = date(&amp;#39;F&amp;#39;, $timestamp);&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &amp;#160; $date[$i][&amp;#39;monthCount&amp;#39;]  = date(&amp;#39;m&amp;#39;, $timestampts);&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &amp;#160; $date[$i][&amp;#39;monthShort&amp;#39;]   = date(&amp;#39;M&amp;#39;, $timestamp);&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &amp;#160; $date[$i][&amp;#39;daysInMonth&amp;#39;] = date(&amp;#39;t&amp;#39;, $timestamp);&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &amp;#160; $date[$i][&amp;#39;year&amp;#39;] &amp;#160;&amp;#160;&amp;#160;        &amp;#160;= date(&amp;#39;Y&amp;#39;, $timestamp);&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &amp;#160; $date[$i][&amp;#39;yearShort&amp;#39;]&amp;#160;    = date(&amp;#39;y&amp;#39;, $timestamp);&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &amp;#160; $month--;&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &amp;#160; $i++;&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; }&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; return $date;&lt;br&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;p&gt;&lt;br&gt;calling the function&lt;p&gt;print_r(getLast12MonthsDetails());&lt;p&gt;will return the following details in an array&lt;p&gt;Array&lt;br&gt;(&lt;br&gt;    [1] =&amp;gt; Array&lt;br&gt;        (&lt;br&gt;            [month] =&amp;gt; July&lt;br&gt;            [monthCount] =&amp;gt; 12&lt;br&gt;            [monthShort] =&amp;gt; Jul&lt;br&gt;            [daysInMonth] =&amp;gt; 31&lt;br&gt;            [year] =&amp;gt; 2009&lt;br&gt;            [yearShort] =&amp;gt; 09&lt;br&gt;        )&lt;p&gt;    [2] =&amp;gt; Array&lt;br&gt;        (&lt;br&gt;            [month] =&amp;gt; June&lt;br&gt;            [monthCount] =&amp;gt; 12&lt;br&gt;            [monthShort] =&amp;gt; Jun&lt;br&gt;            [daysInMonth] =&amp;gt; 30&lt;br&gt;            [year] =&amp;gt; 2009&lt;br&gt;            [yearShort] =&amp;gt; 09&lt;br&gt;        )&lt;p&gt;    [3] =&amp;gt; Array&lt;br&gt;        (&lt;br&gt;            [month] =&amp;gt; May&lt;br&gt;            [monthCount] =&amp;gt; 12&lt;br&gt;            [monthShort] =&amp;gt; May&lt;br&gt;            [daysInMonth] =&amp;gt; 31&lt;br&gt;            [year] =&amp;gt; 2009&lt;br&gt;            [yearShort] =&amp;gt; 09&lt;br&gt;        )&lt;p&gt;    [4] =&amp;gt; Array&lt;br&gt;        (&lt;br&gt;            [month] =&amp;gt; April&lt;br&gt;            [monthCount] =&amp;gt; 12&lt;br&gt;            [monthShort] =&amp;gt; Apr&lt;br&gt;            [daysInMonth] =&amp;gt; 30&lt;br&gt;            [year] =&amp;gt; 2009&lt;br&gt;            [yearShort] =&amp;gt; 09&lt;br&gt;        )&lt;p&gt;    [5] =&amp;gt; Array&lt;br&gt;        (&lt;br&gt;            [month] =&amp;gt; March&lt;br&gt;            [monthCount] =&amp;gt; 12&lt;br&gt;            [monthShort] =&amp;gt; Mar&lt;br&gt;            [daysInMonth] =&amp;gt; 31&lt;br&gt;            [year] =&amp;gt; 2009&lt;br&gt;            [yearShort] =&amp;gt; 09&lt;br&gt;        )&lt;p&gt;    [6] =&amp;gt; Array&lt;br&gt;        (&lt;br&gt;            [month] =&amp;gt; February&lt;br&gt;            [monthCount] =&amp;gt; 12&lt;br&gt;            [monthShort] =&amp;gt; Feb&lt;br&gt;            [daysInMonth] =&amp;gt; 28&lt;br&gt;            [year] =&amp;gt; 2009&lt;br&gt;            [yearShort] =&amp;gt; 09&lt;br&gt;        )&lt;p&gt;    [7] =&amp;gt; Array&lt;br&gt;        (&lt;br&gt;            [month] =&amp;gt; January&lt;br&gt;            [monthCount] =&amp;gt; 12&lt;br&gt;            [monthShort] =&amp;gt; Jan&lt;br&gt;            [daysInMonth] =&amp;gt; 31&lt;br&gt;            [year] =&amp;gt; 2009&lt;br&gt;            [yearShort] =&amp;gt; 09&lt;br&gt;        )&lt;p&gt;    [8] =&amp;gt; Array&lt;br&gt;        (&lt;br&gt;            [month] =&amp;gt; December&lt;br&gt;            [monthCount] =&amp;gt; 12&lt;br&gt;            [monthShort] =&amp;gt; Dec&lt;br&gt;            [daysInMonth] =&amp;gt; 31&lt;br&gt;            [year] =&amp;gt; 2008&lt;br&gt;            [yearShort] =&amp;gt; 08&lt;br&gt;        )&lt;p&gt;    [9] =&amp;gt; Array&lt;br&gt;        (&lt;br&gt;            [month] =&amp;gt; November&lt;br&gt;            [monthCount] =&amp;gt; 12&lt;br&gt;            [monthShort] =&amp;gt; Nov&lt;br&gt;            [daysInMonth] =&amp;gt; 30&lt;br&gt;            [year] =&amp;gt; 2008&lt;br&gt;            [yearShort] =&amp;gt; 08&lt;br&gt;        )&lt;p&gt;    [10] =&amp;gt; Array&lt;br&gt;        (&lt;br&gt;            [month] =&amp;gt; October&lt;br&gt;            [monthCount] =&amp;gt; 12&lt;br&gt;            [monthShort] =&amp;gt; Oct&lt;br&gt;            [daysInMonth] =&amp;gt; 31&lt;br&gt;            [year] =&amp;gt; 2008&lt;br&gt;            [yearShort] =&amp;gt; 08&lt;br&gt;        )&lt;p&gt;    [11] =&amp;gt; Array&lt;br&gt;        (&lt;br&gt;            [month] =&amp;gt; September&lt;br&gt;            [monthCount] =&amp;gt; 12&lt;br&gt;            [monthShort] =&amp;gt; Sep&lt;br&gt;            [daysInMonth] =&amp;gt; 30&lt;br&gt;            [year] =&amp;gt; 2008&lt;br&gt;            [yearShort] =&amp;gt; 08&lt;br&gt;        )&lt;p&gt;    [12] =&amp;gt; Array&lt;br&gt;        (&lt;br&gt;            [month] =&amp;gt; August&lt;br&gt;            [monthCount] =&amp;gt; 12&lt;br&gt;            [monthShort] =&amp;gt; Aug&lt;br&gt;            [daysInMonth] =&amp;gt; 31&lt;br&gt;            [year] =&amp;gt; 2008&lt;br&gt;            [yearShort] =&amp;gt; 08&lt;br&gt;        )&lt;p&gt;)&lt;p&gt;From the above array, we can get all the details of last 12 months.&lt;br&gt;hope that this will helpful for you guys.&lt;p&gt;happy PHPing&lt;p&gt;I wish, you guys, please comment about this post in following box.</description><link>http://phpqa.blogspot.com/2009/07/function-to-find-out-last-12-months.html</link><author>noreply@blogger.com (jj)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2820984862098008600.post-4044930415708698578</guid><pubDate>Tue, 21 Jul 2009 10:56:00 +0000</pubDate><atom:updated>2009-09-21T11:57:20.438+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">CMS</category><category domain="http://www.blogger.com/atom/ns#">elgg</category><title>Riverdashboard in Elgg</title><description>The river is an activity stream containing descriptions of activities. In new elgg there is a plugin called “riverdashboard” , And you can add river for your plugins too.Each river may be added after an activity such as add delete etc .You can use the following function for doing this.&lt;br /&gt;&lt;br /&gt;add_to_river($viewname,$actionname,$userguid,$entityguid);&lt;br /&gt;&lt;br /&gt;      The first parameter $viewname is the name of the view that will display the river item and the next one $actionname is  the action and the other two parameters are the guid of the user performing the action, and the guid of the entity being acted on. &lt;br /&gt;&lt;br /&gt;Elgg recommends the view location of  the river views as follows      /river/classname/event, where classname is the class you’re interested in (ElggObject for objects, ElggUser for users, and so on) and event is the event (create, update, delete and so on).&lt;br /&gt;&lt;br /&gt;River item information will be passed in an object called $vars['item'], which contains two  important parameters $vars['item']-&gt;subject_guid that is the user guid and the action guid that is the $vars['item']-&gt;object_guid .</description><link>http://phpqa.blogspot.com/2009/07/riverdashboard-in-elgg.html</link><author>noreply@blogger.com (jj)</author><thr:total>0</thr:total></item></channel></rss>