<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vijaya Kumar Blog &#187; PHP</title>
	<atom:link href="http://vijayakumar.org/category/php/feed" rel="self" type="application/rss+xml" />
	<link>http://vijayakumar.org</link>
	<description>(Stunning PHP/MYSQL/AJAX/SEO Tips)</description>
	<lastBuildDate>Fri, 03 Sep 2010 02:06:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Use isset() Instead of strlen()</title>
		<link>http://vijayakumar.org/use-isset-instead-of-strlen.html</link>
		<comments>http://vijayakumar.org/use-isset-instead-of-strlen.html#comments</comments>
		<pubDate>Sat, 17 Jul 2010 00:53:37 +0000</pubDate>
		<dc:creator>Vijaya Kumar</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Use isset()]]></category>

		<guid isPermaLink="false">http://vijayakumar.org/?p=953</guid>
		<description><![CDATA[This is actually a neat trick. Here is the example: &#60;?php if (isset($username[5])) { // The username is at least six characters long. } ?&#62; When you treat strings as arrays, each character in the string is an element in the array. By determining whether a particular element exists, you can determine whether the string [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; font-size: small;"><span style="line-height: 18px; white-space: pre;"><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: small;"><span style="line-height: 19px; white-space: normal;">This is actually a neat trick. Here is the example:</span></span></span></span></p>
<blockquote>
<pre>&lt;?php

if (isset($username[5])) {
    // The username is at least six characters long.
}

?&gt;</pre>
</blockquote>
<p>When you treat strings as arrays, each character in the string is an element in the array. By determining whether a particular element exists, you can determine whether the string is at least that many characters long. (Note that the first character is element 0, so $username[5] is the sixth character in $username.)</p>
<p>The reason this is slightly faster than strlen() is complicated. The simple explanation is that strlen() is a function, and isset() is a language construct. Generally speaking, calling a function is more expensive than using a language construct.</p>
]]></content:encoded>
			<wfw:commentRss>http://vijayakumar.org/use-isset-instead-of-strlen.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shortcut the else in PHP</title>
		<link>http://vijayakumar.org/shortcut-the-else-in-php.html</link>
		<comments>http://vijayakumar.org/shortcut-the-else-in-php.html#comments</comments>
		<pubDate>Fri, 09 Jul 2010 14:23:24 +0000</pubDate>
		<dc:creator>Vijaya Kumar</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Shortcut the else]]></category>

		<guid isPermaLink="false">http://vijayakumar.org/?p=930</guid>
		<description><![CDATA[This tip accidentally stumbles upon a useful practice, which is to always initialize variables before you use them. Consider a conditional statement that determines whether a user is an administrator based on the username: &#60;?php if (auth($username) == 'admin') { $admin = TRUE; } else { $admin = FALSE; } ?&#62; This seems safe enough, [...]]]></description>
			<content:encoded><![CDATA[<p>This tip accidentally stumbles upon a useful practice, which is to  always initialize variables before you use them. Consider a conditional  statement that determines whether a user is an administrator based on  the username:</p>
<blockquote>
<pre>&lt;?php

if (auth($username) == 'admin') {
    $admin = TRUE;
} else {
    $admin = FALSE;
}

?&gt;
</pre>
</blockquote>
<p>This seems safe enough, because it’s easy to comprehend at a glance.  Imagine a slightly more elaborate example that sets variables for name  and email as well, for convenience:</p>
<blockquote>
<pre>&lt;?php

if (auth($username) == 'admin') {
    $name = 'Administrator';
    $email = 'admin@example.org';
    $admin = TRUE;
} else {
    /* Get the name and email from the database. */
    $query = $db-&gt;prepare('SELECT name, email
                           FROM   users
                           WHERE  username = :username');
    $query-&gt;execute(array('username' =&gt; $clean['username']));
    $result = $query-&gt;fetch(PDO::FETCH_ASSOC);
    $name = $result['name'];
    $email = $result['email'];
    $admin = FALSE;
}

?&gt;
</pre>
</blockquote>
<p>Because $admin is still always explicitly set to either TRUE or FALSE,  all is well, but if a developer later adds an elseif, there’s an  opportunity to forget:</p>
<blockquote>
<pre>&lt;?php

if (auth($username) == 'admin') {
    $name = 'Administrator';
    $email = 'admin@example.org';
    $admin = TRUE;
} elseif (auth($username) == 'mod') {
    $name = 'Moderator';
    $email = 'mod@example.org';
    $moderator = TRUE;
} else {
    /* Get the name and email. */
    $query = $db-&gt;prepare('SELECT name, email
                           FROM   users
                           WHERE  username = :username');
    $query-&gt;execute(array('username' =&gt; $clean['username']));
    $result = $query-&gt;fetch(PDO::FETCH_ASSOC);
    $name = $result['name'];
    $email = $result['email'];
    $admin = FALSE;
    $moderator = FALSE;
}

?&gt;
</pre>
</blockquote>
<p>If a user provides a username that triggers the elseif condition,  $admin is not initialized. This can lead to unwanted behavior, or worse,  a security vulnerability. Additionally, a similar situation now exists  for $moderator, which is not initialized in the first condition.</p>
<p>By  first initializing $admin and $moderator, it’s easy to avoid this  scenario altogether:</p>
<blockquote>
<pre>&lt;?php

$admin = FALSE;
$moderator = FALSE;

if (auth($username) == 'admin') {
    $name = 'Administrator';
    $email = 'admin@example.org';
    $admin = TRUE;
} elseif (auth($username) == 'mod') {
    $name = 'Moderator';
    $email = 'mod@example.org';
    $moderator = TRUE;
} else {
    /* Get the name and email. */
    $query = $db-&gt;prepare('SELECT name, email
                           FROM   users
                           WHERE  username = :username');
    $query-&gt;execute(array('username' =&gt; $clean['username']));
    $result = $query-&gt;fetch(PDO::FETCH_ASSOC);
    $name = $result['name'];
    $email = $result['email'];
}

?&gt;</pre>
</blockquote>
<p>Regardless of what the rest of the code does, it’s now clear that  $admin is FALSE unless it is explicitly set to something else, and the  same is true for $moderator. This also hints at another good security  practice, which is to fail safely. The worst that can happen as a result  of not modifying $admin or $moderator in any of the conditions is that  someone who is an administrator or moderator is not treated as one.</p>
<p>If  you want to shortcut something, and you’re feeling a little  disappointed that our example includes an else, we have a bonus tip that  might interest you. We’re not certain it can be considered a shortcut,  but we hope it’s helpful nonetheless.</p>
<p>Consider a function that  determines whether a user is authorized to view a particular page:</p>
<blockquote>
<pre>&lt;?php

function authorized($username, $page) {
    if (!isBlacklisted($username)) {
        if (isAdmin($username)) {
            return TRUE;
        } elseif (isAllowed($username, $page)) {
            return TRUE;
        } else {
            return FALSE;
        }
    } else {
        return FALSE;
    }
}

?&gt;
</pre>
</blockquote>
<p>This example is actually pretty simple, because there are only three  rules to consider: administrators are always allowed access; those who  are blacklisted are never allowed access; and isAllowed() determines  whether anyone else has access. (A special case exists when an  administrator is blacklisted, but that is an unlikely possibility, so  we’re ignoring it here.) We use functions for the rules to keep the code  simple and to focus on the logical structure.</p>
<p>There are numerous  ways this example can be improved. If you want to reduce the number of  lines, a compound conditional can help:</p>
<blockquote>
<pre>&lt;?php

function authorized($username, $page) {
    if (!isBlacklisted($username)) {
        if (isAdmin($username) || isAllowed($username, $page)) {
            return TRUE;
        } else {
            return FALSE;
        }
    } else {
        return FALSE;
    }
}

?&gt;</pre>
</blockquote>
<p>Finally, this can be reduced to a single return:</p>
<blockquote>
<pre>&lt;?php

function authorized($username, $page) {
    return (!isBlacklisted($username) &amp;&amp; (isAdmin($username) || isAllowed($username, $page));
}

?&gt;</pre>
</blockquote>
<p>If your goal is to reduce the number of lines, you’re done. However, note that we’re using isBlacklisted(), isAdmin(), and isAllowed() as placeholders. Depending on what’s involved in making these determinations, reducing everything to a compound conditional may not be as attractive.</p>
<p>This brings us to our tip. A return immediately exits the function, so if you return as soon as possible, you can express these rules very simply:</p>
<blockquote>
<pre>&lt;?php

function authorized($username, $page) {

    if (isBlacklisted($username)) {
        return FALSE;
    }

    if (isAdmin($username)) {
        return TRUE;
    }

    return isAllowed($username, $page);
}

?&gt;</pre>
</blockquote>
<p>This uses more lines of code, but it’s very simple and unimpressive (we’re proudest of our code when it’s the least impressive). More importantly, this approach reduces the amount of context you must keep up with. For example, as soon as you’ve determined whether the user is blacklisted, you can safely forget about it. This is particularly helpful when your logic is more complicated.</p>
]]></content:encoded>
			<wfw:commentRss>http://vijayakumar.org/shortcut-the-else-in-php.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Know the Difference Between Comparison Operators</title>
		<link>http://vijayakumar.org/know-the-difference-between-comparison-operators.html</link>
		<comments>http://vijayakumar.org/know-the-difference-between-comparison-operators.html#comments</comments>
		<pubDate>Wed, 07 Jul 2010 02:15:45 +0000</pubDate>
		<dc:creator>Vijaya Kumar</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Comparison Operators]]></category>

		<guid isPermaLink="false">http://www.vijayakumar.org/?p=926</guid>
		<description><![CDATA[This is a good tip, but it is missing a practical example that demonstrates when a non-strict comparison can cause problems. If you use strpos() to determine whether a substring exists within a string (it returns FALSE if the substring is not found), the results can be misleading: &#60;?php $authors = 'Vijay &#38; Jana'; if (strpos($authors, 'Vijay')) [...]]]></description>
			<content:encoded><![CDATA[<p style="margin-bottom: 1.15em;">This is a good tip, but it is missing a practical example that demonstrates when a non-strict comparison can cause problems.</p>
<p style="margin-bottom: 1.15em;">If you use strpos() to determine whether a substring exists within a string (it returns FALSE if the substring is not found), the results can be misleading:</p>
<blockquote>
<pre>&lt;?php

$authors = 'Vijay &amp; Jana';

if (strpos($authors, 'Vijay')) {
    echo 'Vijay is an author.';
} else {
    echo 'Jana is not an author.';
}

?&gt;</pre>
</blockquote>
<p>Because the substring Vijay occurs at the very beginning of Vijay &amp; Jana, strpos()correctly returns 0, indicating the first position in the string. Because the conditional statement treats this as a Boolean, it evaluates to FALSE, and the condition fails. In other words, it looks like Vijay is not an author, but he is!</p>
<p>This can be corrected with a strict comparison:</p>
<blockquote>
<pre>&lt;?php

if (strpos($authors, 'Vijay') !== FALSE) {
    echo 'Vijay is an author.';
} else {
    echo 'Jana is not an author.';
}

?&gt;</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://vijayakumar.org/know-the-difference-between-comparison-operators.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Class to custom SQL DATETIME format using php</title>
		<link>http://vijayakumar.org/class-to-custom-sql-datetime-format-using-php.html</link>
		<comments>http://vijayakumar.org/class-to-custom-sql-datetime-format-using-php.html#comments</comments>
		<pubDate>Sat, 28 Nov 2009 07:53:43 +0000</pubDate>
		<dc:creator>Vijaya Kumar</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[custom sql datetime format]]></category>
		<category><![CDATA[sql datetime format]]></category>

		<guid isPermaLink="false">http://www.vijayakumar.org/?p=755</guid>
		<description><![CDATA[This class will be used to custom the SQL Datetime format in your style. This may very useful for web developers to make their work easy. Class (Store as &#8220;sql.date.class.php&#8220;): &#60;?php class FormatDate { public function Date($SQLdate, $format) { $maketime = strtotime($SQLdate); return date($format,$maketime); } } $dateobj = new FormatDate; ?&#62; Implementation (Store as &#8220;index.php&#8220;): [...]]]></description>
			<content:encoded><![CDATA[<p>This class will be used to custom the SQL Datetime format in your style. This may very useful for web developers to make their work easy.</p>
<p><span style="text-decoration: underline;"><strong>Class (Store as &#8220;</strong>sql.date.class.php<strong>&#8220;):</strong></span></p>
<blockquote><p>&lt;?php</p>
<p>class FormatDate {</p>
<p>public function Date($SQLdate, $format) {</p>
<p>$maketime = strtotime($SQLdate);</p>
<p>return date($format,$maketime);</p>
<p>}<br />
}</p>
<p>$dateobj = new FormatDate;</p>
<p>?&gt;</p></blockquote>
<p><span style="text-decoration: underline;"><strong>Implementation (Store as &#8220;</strong>index.php<strong>&#8220;):</strong></span></p>
<blockquote><p>&lt;?php</p>
<p>require_once &#8220;sql.date.class.php&#8221;;</p>
<p>echo $dateobj-&gt;Date(&#8220;2009-11-28 6:44:07&#8243;,&#8221;F j, Y, g:i a&#8221;); //Argument 1 is a SQL DATETIME format [Call your date format from SQL table], argument 2 is a format which u need.<br />
echo &#8220;&lt;br/&gt;&#8221;;<br />
echo $dateobj-&gt;Date(&#8220;2009-11-28 6:44:07&#8243;,&#8221;m.d.y&#8221;);<br />
echo &#8220;&lt;br/&gt;&#8221;;<br />
echo $dateobj-&gt;Date(&#8220;2009-11-28 6:44:07&#8243;,&#8221;h-i-s, j-m-y, it is w Day&#8221;);<br />
echo &#8220;&lt;br/&gt;&#8221;;<br />
echo $dateobj-&gt;Date(&#8220;2009-11-28 6:44:07&#8243;,&#8217;\i\t \i\s \t\h\e jS \d\a\y.&#8217;);</p>
<p>?&gt;</p></blockquote>
<p>In above class, you want to pass 2 arguments,</p>
<ol>
<li>First Argument will be date, which from SQL (DEFAULT SQL DATETIME FORMAT date(&#8220;Y-n-j g:i:s&#8221;)) table.</li>
<li>Second Argument will be Date format which you need as output.</li>
</ol>
<p>Once above passed arguments are correct, it will returns the date in Date Format, you needed. Download Source here [<a title="Zip" href="http://splendidwebtech.com/downloads/downloads.php?fileID=759330sqldateformatzipdbdateformat.zip" target="_blank"> ZIP Format </a>], [ <a title="http://splendidwebtech.com/downloads/downloads.php?fileID=477322dateformat-rardbdateformat.rar" href="http://splendidwebtech.com/downloads/downloads.php?fileID=477322dateformat-rardbdateformat.rar" target="_blank">RAR Format</a> ] [<span style="color: #ff0000;">Please Comment for updations</span>]</p>
]]></content:encoded>
			<wfw:commentRss>http://vijayakumar.org/class-to-custom-sql-datetime-format-using-php.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySql injection protection class in php</title>
		<link>http://vijayakumar.org/mysql-injection-protection-class-in-php.html</link>
		<comments>http://vijayakumar.org/mysql-injection-protection-class-in-php.html#comments</comments>
		<pubDate>Tue, 24 Nov 2009 06:49:49 +0000</pubDate>
		<dc:creator>Vijaya Kumar</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Security]]></category>
		<category><![CDATA[MySql injection protection]]></category>
		<category><![CDATA[MySql injection protection class]]></category>

		<guid isPermaLink="false">http://www.vijayakumar.org/?p=743</guid>
		<description><![CDATA[What is Mysql Injection? SQL injection refers to the act of someone inserting a MySQL statement to be run on your database without your knowledge. Injection usually occurs when you ask a user for input, like their name, and instead of a name they give you a MySQL statement that you will unknowingly run on [...]]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: underline;"><strong>What is Mysql Injection?</strong></span></p>
<p>SQL injection refers to the act of someone inserting a MySQL statement to be run on your database without your knowledge. Injection usually occurs when you ask a user for input, like their name, and instead of a name they give you a MySQL statement that you will unknowingly run on your database. Source &#8211; <a title="http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php" href="http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php" target="_blank">tizag.com</a>.</p>
<p><span style="text-decoration: underline;"><strong>Protection Class in PHP:</strong></span></p>
<p>This is my own code to filtered unwanted inputs by user: [ <span style="color: #ff0000;">Don't forget to comment here for improvement</span> ]</p>
<blockquote><p>&lt;?php</p>
<p>class SQLProcess {</p>
<p>function filter($array) {</p>
<p>$keyarray = array();<br />
$valuearray = array();<br />
$outarray = array();</p>
<p>while (list($key, $value) = each($array)) {</p>
<p>if(get_magic_quotes_runtime()) {<br />
set_magic_quotes_runtime(false);<br />
}</p>
<p>$badWords = &#8220;(delete)|(update)|(union)|(insert)|(drop)|(http)|(&#8211;)|(script)|(iframe)|(alert)|(XSS)&#8221;;</p>
<p>//Values Filter<br />
$filtervalues = eregi_replace($badWords,&#8221;&#8216;&#8221;, $value);<br />
$filtervalues = mysql_real_escape_string($filtervalues);<br />
$filtervalues = htmlentities($filtervalues,ENT_QUOTES);</p>
<p>//Key Filter<br />
$filterkeys = eregi_replace($badWords, &#8220;&#8221;, $key);<br />
$filterkeys = mysql_real_escape_string($filterkeys);<br />
$filterkeys = htmlentities($filterkeys,ENT_QUOTES);</p>
<p>array_push($keyarray,$filterkeys);<br />
array_push($valuearray,$filtervalues);</p>
<p>}<br />
$outarray = array_combine($keyarray, $valuearray);<br />
return $outarray;<br />
}</p>
<p>}</p>
<p>$Process = new SQLProcess;</p>
<p>?&gt;</p></blockquote>
<p><span style="text-decoration: underline;"><strong>Example Usage:</strong></span></p>
<p>$filter = $Process-&gt;filter($_REQUEST);</p>
<p>print_r($filter);</p>
<p>$_REQUEST is an array with total inputs given by users through form.</p>
<p><strong><span style="text-decoration: underline;">Note</span>:</strong> Comment here to improve this class. And also mysql_real_escape_string() will works only when Database is used(connected). <span style="color: #ff0000;">If you not using Database! replace mysql_real_escape_string with addslashes.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://vijayakumar.org/mysql-injection-protection-class-in-php.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Alternate method for $_SERVER[&#039;SCRIPT_NAME&#039;] to find exact filename</title>
		<link>http://vijayakumar.org/alternate-method-for-serverscript_name-to-find-exact-filename.html</link>
		<comments>http://vijayakumar.org/alternate-method-for-serverscript_name-to-find-exact-filename.html#comments</comments>
		<pubDate>Thu, 29 Oct 2009 02:45:16 +0000</pubDate>
		<dc:creator>Vijaya Kumar</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.vijayakumar.org/?p=724</guid>
		<description><![CDATA[Now a days, all web developers/bloggers/SEO persons are using beautiful URL&#8217;s. Due to using beautiful URL&#8217;s, users can&#8217;t find, from which file name exact page is working. For Ex :- http://www.vijayakumar.org/profile/vijayakumar (It&#8217;s beautiful URL). But above mentioned URL will runs from file called profile.php [just guess]. How to find profile.php is a file? Is it [...]]]></description>
			<content:encoded><![CDATA[<p>Now a days, all web developers/bloggers/SEO persons are using beautiful URL&#8217;s. Due to using beautiful URL&#8217;s, users can&#8217;t find, from which file name exact page is working. For Ex :- http://www.vijayakumar.org/profile/vijayakumar (It&#8217;s beautiful URL). But above mentioned URL will runs from file called <strong>profile.php </strong><em>[just guess]</em>. How to find profile.php is a file? Is it possible? Yes, it&#8217;s possible. You can use $_SERVER['SCRIPT_NAME'];  to find out the file name. Instead of this, below code will more helpfull,</p>
<blockquote><p>&lt;?php<br />
$sPage = explode(&#8220;/&#8221;, $_SERVER['PHP_SELF']);<br />
$URL= $sPage[count($sPage)-1];<br />
?&gt;</p></blockquote>
<p><strong>For Example:</strong></p>
<p>http://www.vijayakumar.org/profile/vijay</p>
<p>Output will be profile.php [file name changes depends upon file used]</p>
]]></content:encoded>
			<wfw:commentRss>http://vijayakumar.org/alternate-method-for-serverscript_name-to-find-exact-filename.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Combine 2 MySql results using array on PHP</title>
		<link>http://vijayakumar.org/combine-2-mysql-results-using-array-on-php.html</link>
		<comments>http://vijayakumar.org/combine-2-mysql-results-using-array-on-php.html#comments</comments>
		<pubDate>Fri, 28 Aug 2009 18:48:25 +0000</pubDate>
		<dc:creator>Vijaya Kumar</dc:creator>
				<category><![CDATA[MYSQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.vijayakumar.org/?p=625</guid>
		<description><![CDATA[Main theme of this article is, searching values in 2 different MySql queries and combining both results as array using array_combine() and array_push(). Explanation is given under source code. &#60;?php //connection parameters $username = &#8220;root&#8221;; $password = &#8220;&#8221;; $dbhost = &#8220;localhost&#8221;; $database = &#8220;test&#8221;; //Array creation $table1array = array(); $table2array = array(); $finalarray = array(); [...]]]></description>
			<content:encoded><![CDATA[<p>Main theme of this article is, searching values in 2 different MySql queries and combining both results as array using array_combine() and array_push().</p>
<p>Explanation is given under source code.</p>
<blockquote><p>&lt;?php<br />
//connection parameters<br />
$username = &#8220;root&#8221;;<br />
$password = &#8220;&#8221;;<br />
$dbhost = &#8220;localhost&#8221;;<br />
$database = &#8220;test&#8221;;</p>
<p>//Array creation<br />
$table1array = array();<br />
$table2array = array();<br />
$finalarray = array();</p>
<p>//connect to database server<br />
$dbconnection = mysql_connect($dbhost, $username, $password) or die(&#8220;Could not connect to MySQL Database&#8221;);<br />
echo &#8220;Connection Success!!!&#8221;;</p>
<p>//connect to database<br />
$dbhandle = mysql_select_db($database, $dbconnection) or die(&#8220;Could not select the test database&#8221;);</p>
<p>//Queries to combine<br />
$t1 = &#8220;select * from `table1`&#8221;;<br />
$t2 = &#8220;select * from `table2`&#8221;;</p>
<p>$table1query = mysql_query($t1);<br />
$table2query = mysql_query($t2);</p>
<p>//Count the number of records are equal.<br />
$t1_count = mysql_num_rows($table1query);<br />
$t2_count = mysql_num_rows($table2query);</p>
<p>//If not equal, error will be produced<br />
if($t1_count != $t2_count) {</p>
<p>echo &#8221; But, both parameters should have an equal number of elements&#8221;;<br />
exit;</p>
<p>}</p>
<p>//First table query to push, first table values into array by using array_push<br />
while($table1row = mysql_fetch_array($table1query)) {</p>
<p>$table1value = $table1row['table1_value'];<br />
array_push($table1array, $table1value);</p>
<p>}</p>
<p>//Second table query to push, second table values into array by using array_push<br />
while($table2row = mysql_fetch_array($table2query)) {</p>
<p>$table2value = $table2row['table2_value'];<br />
array_push($table2array, $table2value);</p>
<p>}</p>
<p>//Combine above generated arrays and combine into one<br />
$finalarray = array_combine($table1array, $table2array);</p>
<p>//Print the output<br />
print_r($finalarray); exit;</p>
<p>?&gt;</p></blockquote>
<p><span style="text-decoration: underline;"><strong>EXPLANATION:</strong></span></p>
<p><span style="text-decoration: underline;"><strong>Create tables:</strong></span></p>
<p>Connect to database with database username and password. Create database called “test” followed by creating 2 tables. Name those tables as ‘table1’ and ‘table2’. Inside both tables create 2 fields with names ‘t1_id’, ‘table1_value’ -&gt; for table1 and ‘t2_id’, ‘table2_value’ -&gt; for table2. Then insert values into 2 tables in fields ‘table1_value’ and ‘table2_value’ equally. Remember that, both tables’ values should be equal.</p>
<p><strong><span style="text-decoration: underline;">Create 3 arrays:</span></strong><strong><strong><br />
</strong></strong>Return to PHP source code, Create 3 arrays using array() in names $table1array, $table2array, $finalarray. $table1array is to hold values from table 1 and $table2array is to hold values from table 2. $finalarray is to combine arrays $table1array and $table2array.</p>
<p><strong><span style="text-decoration: underline;">Execute 2 queries and compare:</span></strong></p>
<p>$t1 and $t2 are MySql queries to combine values. Execute the 2 tables’ using mysql_query(). Count number of rows using mysql_num_rows(); Because values of 2 tables should be same, otherwise it will returns warning message.[ This is validated on next line 32 using if statement].</p>
<p><span style="text-decoration: underline;"><strong><strong><strong>Push values into array:</strong></strong></strong></span></p>
<p>If both table 1 and table 2 values are equal, it will run 40th line. There we using while loop to get table1 values into array by name $table1array using array_push(). Now all values of table 1 are moved to $table1array. Next line 48th, having another while loop, It’s also get table 2 values into array by name $table2array using array_push().</p>
<p><span style="text-decoration: underline;"><strong><strong><strong>Combine 2 arrays:</strong></strong></strong></span></p>
<p>We got 2 arrays which holding 2 different set of values. Combine, 2 arrays $table1array and $table2array by using array_push(). And named final array  $finalarray. Print the result print_r($finalarray);. That’s all. We achieved.</p>
<p><span style="text-decoration: underline;"><strong><strong><strong>Final result:</strong></strong></strong></span></p>
<p>If 2 tables (table1 and table 2) values are not equal. Output will be,</p>
<blockquote><p>Connection Success!!! But, both parameters should have an equal number of elements</p></blockquote>
<p>Otherwise output will look like [data can be differ as per ur input],</p>
<blockquote><p>Connection Success!!!Array ( [1] =&gt; vijay [2] =&gt; jana [3] =&gt; selvaraj [4] =&gt; welcome [5] =&gt; hello world )</p></blockquote>
<p><span style="text-decoration: underline;"><strong><strong><strong>Download Source code:</strong></strong></strong></span></p>
<p><span style="text-decoration:line-through;"><a title="Source code" href="http://www.splendidwebtech.com/code/download.php?file=CombineMySqlresults.zip" target="_blank">http://www.splendidwebtech.com/code/download.php?file=CombineMySqlresults.zip</a></span></p>
<p><a title="Download link" href="http://rapidshare.com/files/280269160/CombineMySqlresults.zip.html" target="_blank">http://rapidshare.com/files/280269160/CombineMySqlresults.zip.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://vijayakumar.org/combine-2-mysql-results-using-array-on-php.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Easy Multilingual (English &amp; Tamil) Website creation using php</title>
		<link>http://vijayakumar.org/easy-multilangual-english-tamil-website-creation-using-php.html</link>
		<comments>http://vijayakumar.org/easy-multilangual-english-tamil-website-creation-using-php.html#comments</comments>
		<pubDate>Mon, 17 Aug 2009 19:24:12 +0000</pubDate>
		<dc:creator>Vijaya Kumar</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[dynamic PHP for Tamil]]></category>
		<category><![CDATA[Multilangual (English & Tamil)]]></category>
		<category><![CDATA[PHP in tamil]]></category>
		<category><![CDATA[Tamil and English website in PHP]]></category>

		<guid isPermaLink="false">http://www.vijayakumar.org/?p=594</guid>
		<description><![CDATA[This article will help you to learn how multi lingual web sites can be done by your own. This is a try by testing with 2 languages (English &#38; Tamil). This may useful for web developers for creating multi language web sites. Ok, let we start.., It’s very simple work, by fetching data from 2 [...]]]></description>
			<content:encoded><![CDATA[<p>This article will help you to learn how multi lingual web sites can be done by your own. This is a try by testing with 2 languages (English &amp; Tamil). This may useful for web developers for creating multi language web sites.</p>
<p>Ok, let we start..,</p>
<p>It’s very simple work, by fetching data from 2 different databases. In these 2 databases, one will holds data about Tamil (or any language) and another will holds English. Once, Tamil language is clicked, data from Tamil (or any language) database will fetched and if English language is clicked, data from English database will fetched. So, you need to know 2 things very clearly,</p>
<p>1)     How to handle 2 different databases in a project? and</p>
<p>2)     How to insert Tamil language (or any language) into DB?</p>
<p>Ok let we see the answers for above questions,</p>
<p>1)<strong> How to handle 2 databases in a project?</strong> (This is my logic; you can use by your own, if u has any method to call databases)</p>
<blockquote><p>&lt;?php</p>
<p>session_start();</p>
<p>ob_start();</p>
<p>if(isset($_REQUEST['ta']))</p>
<p>{</p>
<p>$sess = $_REQUEST['ta']; //Tamil language</p>
<p>$_SESSION['ta']=$sess;</p>
<p>$database = &#8216;multitamil&#8217;;</p>
<p>}</p>
<p>else if(isset($_REQUEST['en']))</p>
<p>{</p>
<p>unset($_SESSION['ta']);</p>
<p>$sess = $_REQUEST['en']; //English language</p>
<p>$_SESSION['en']=$sess;</p>
<p>$database = &#8216;multienglish&#8217;;</p>
<p>}</p>
<p>mysql_connect(&#8220;localhost&#8221;,&#8221;root&#8221;,&#8221;") or die(&#8216;Server down for maintenence, please try again later&#8217;);</p>
<p>mysql_select_db($database);</p>
<p>?&gt;</p></blockquote>
<p>In above code, if once Tamil language (or any language) link clicked, pass the variable to the same page as ‘<strong>ta</strong>’ ie., ($_REQUEST['ta']) , like below,</p>
<p><strong>www.youdomain.com/?ta</strong></p>
<p>Once ‘ta’ is set, unset `en` session and set the session as ta. Once ‘<strong>ta</strong>’ set, database for Tamil language will be called. Tamil language Database will be active till session expired.</p>
<p>If, English language is clicked; pass the variable to the same page as ‘<strong>en</strong>’ i.e. ($_REQUEST['en']) , like below,</p>
<p><strong> www.youdomain.com/?en</strong></p>
<p>Once ‘en’ is set, unset ‘<strong>ta</strong>’ session and set the session as en. Once ‘<strong>en</strong>’ set, database for English language will be called.</p>
<p><strong>Note</strong>: Default language is English.</p>
<p>2)  <strong>How to insert Tamil language (or any language) into DB?</strong></p>
<p>If Tamil (or any language) language want to insert into DB means it will store as bulk Unicode characters. So, type Tamil language (or any language) using text box or comment box etc. and submit the form, like given below example,</p>
<blockquote style="text-align: left; ">
<p style="text-align: left; ">&lt;form id=&#8221;form1&#8243; method=&#8221;post&#8221; action=&#8221;&lt;?php $_SERVER['PHP_SELF'];?&gt;&#8221;&gt;</p>
<p style="text-align: left; ">&lt;textarea name=&#8221;language&#8221;&gt;&lt;/textarea&gt;</p>
<p style="text-align: left; ">&lt;input name=&#8221;submit&#8221; type=&#8221;submit&#8221; /&gt;</p>
<p>&lt;/form&gt;</p></blockquote>
<p>Store the content in Tamil (any) Language database by using insert query. You didn’t need to worry about Unicode conversion, it will automatically converted by browsers while submission. See the link for Unicode chart supported by browsers by <a title="unicode" href="http://www.alanwood.net/unicode/browser-coverage.html" target="_blank">clicking here</a> .</p>
<div><img class="size-full wp-image-647 alignleft" title="Vijay Name in Tamil" src="http://www.vijayakumar.org/wp-content/uploads/2009/08/tamil_textbox.jpg" alt="Vijay Name in Tamil" width="155" height="31" /></div>
<p>Or use Google transliteration tool for typing (<a title="Google Transletration" href="http://www.google.com/transliterate/" target="_blank">Click here</a>). <strong>Note</strong>: Once typed, copy it and paste it in text box and submit the form. Write insert query to store in Tamil database (or any of your language database).</p>
<p><img class="alignnone size-full wp-image-648" title="tamil_google_tool" src="http://www.vijayakumar.org/wp-content/uploads/2009/08/tamil_google_tool.jpg" alt="tamil google tool Easy Multilingual (English & Tamil) Website creation using php" width="706" height="141" /></p>
<p><strong>Requirements to run this code:</strong></p>
<p>1) PHP Editor,</p>
<p>2) WAMP server or your own server,</p>
<p>3) Basic knowledge in PHP, MYSQL.</p>
<p><strong>Features of this code:</strong></p>
<p>1) Displays same content in both Tamil Language and English,</p>
<p>2) Search option in both English and Tamil,</p>
<p>3) Search terms will be highlighted with different color in both English and Tamil language.</p>
<p><strong>Download:</strong></p>
<p><a title="Multilingual RAR format" href="http://www.vijayakumar.org/code/multilanguage.rar" target="_blank"><strong>Click here</strong></a><strong> [ RAR format ] for download [ unlimited download ]</strong></p>
<p><a title="Multilingual zip format" href="http://www.vijayakumar.org/code/170984MultiLanguagecontentsmultilanguage.zip" target="_blank"><strong>Click here</strong></a><strong> [ ZIP format ] for download [ unlimited download ]</strong></p>
<p><em>[ Any problem in downloading, please report me ]</em></p>
<p><strong>Installation:</strong></p>
<p>1) Download the source code, and unzip it.</p>
<p>2) Place it in your server,</p>
<p>3) Open your database; create 2 databases name as multienglish and multitamil. Import the sql files (multienglish.sql &amp; multitamil.sql) into database. (See the Database folder).</p>
<p>4) Change database username and password in ‘<strong>connect.php</strong>’ file.</p>
<p>5) Run the code now.</p>
]]></content:encoded>
			<wfw:commentRss>http://vijayakumar.org/easy-multilangual-english-tamil-website-creation-using-php.html/feed</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>How to check online status for AIM, Yahoo!, MSN, Skype and ICQ users in PHP</title>
		<link>http://vijayakumar.org/how-to-check-online-status-for-aim-yahoo-msn-skype-and-icq-users-in-php.html</link>
		<comments>http://vijayakumar.org/how-to-check-online-status-for-aim-yahoo-msn-skype-and-icq-users-in-php.html#comments</comments>
		<pubDate>Wed, 12 Aug 2009 18:32:17 +0000</pubDate>
		<dc:creator>Vijaya Kumar</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ICQ users in PHP]]></category>
		<category><![CDATA[IM]]></category>
		<category><![CDATA[MSN]]></category>
		<category><![CDATA[Online status for AIM]]></category>
		<category><![CDATA[Skype]]></category>
		<category><![CDATA[Yahoo]]></category>

		<guid isPermaLink="false">http://www.vijayakumar.org/?p=551</guid>
		<description><![CDATA[You&#8217;re probably registered on at least one forum. And you&#8217;ve no doubt seen that in your forum profile, you can add your favourite Instant Messaging (IM) profile details, and other users can see if you&#8217;re online. You in turn, can see who else is online as well. Well what if you want to add that [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;re probably registered on at least one forum. And you&#8217;ve no doubt seen that in your forum profile, you can add your favourite Instant Messaging (IM) profile details, and other users can see if you&#8217;re online. You in turn, can see who else is online as well. Well what if you want to add that status indicator to a website you run? Here are a series of PHP classes that can detect the online/offline status in all of the major IMs.</p>
<ul>
<li><a title="MSN" href="http://www.phpclasses.org/browse/package/3841.html" target="_blank">MSN</a></li>
</ul>
<ul>
<li><a title="Skype" href="http://www.phpclasses.org/browse/package/3842.html" target="_blank">Skype</a></li>
</ul>
<ul>
<li><a title="ICQ" href="http://www.phpclasses.org/browse/package/3843.html" target="_blank">ICQ</a></li>
</ul>
<ul>
<li><a title="AIM" href="http://www.phpclasses.org/browse/package/3844.html" target="_blank">AIM</a></li>
</ul>
<ul>
<li><a title="Yahoo" href="http://www.phpclasses.org/browse/package/3845.html" target="_blank">Yahoo!</a></li>
</ul>
<address>Note:  I did&#8217;t test any above classes.  Do it in your own risk.  I got this info while i googling around internet. Comment me for anything.</address>
]]></content:encoded>
			<wfw:commentRss>http://vijayakumar.org/how-to-check-online-status-for-aim-yahoo-msn-skype-and-icq-users-in-php.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bulk &#8220;One Line&#8221; PHP scripts</title>
		<link>http://vijayakumar.org/bulk-one-line-php-scripts.html</link>
		<comments>http://vijayakumar.org/bulk-one-line-php-scripts.html#comments</comments>
		<pubDate>Tue, 04 Aug 2009 18:32:20 +0000</pubDate>
		<dc:creator>Vijaya Kumar</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Debug $_GET variables]]></category>
		<category><![CDATA[Eliminate duplicate characters]]></category>
		<category><![CDATA[Include using a full unix path]]></category>
		<category><![CDATA[Pass the htaccess/htpassword]]></category>
		<category><![CDATA[Randomly select of one element]]></category>
		<category><![CDATA[Read a flat file]]></category>
		<category><![CDATA[Remove one element from an array]]></category>
		<category><![CDATA[Scrub html output]]></category>
		<category><![CDATA[Validate email address]]></category>
		<category><![CDATA[Validate user name and verify valid MX records]]></category>

		<guid isPermaLink="false">http://www.vijayakumar.org/?p=475</guid>
		<description><![CDATA[Below scripts will be more useful for PHP developers to make their coding fast and efficiency. 1) Eliminate duplicate (or more) characters in a string (the underscore in the example below): $text = preg_replace('#(_)+#','_',$text); 2) Randomly select of one element out of an array: $image = $image_array[array_rand($image_array)]; 3) Pass the htaccess/htpassword authenticated user to a [...]]]></description>
			<content:encoded><![CDATA[<p>Below scripts will be more useful for PHP developers to make their coding fast and efficiency.</p>
<p>1) <strong>Eliminate duplicate</strong> (or more) <strong>characters</strong> in a string (the underscore in the example below):<br />
<code>$text = preg_replace('#(_)+#','_',$text);</code></p>
<p>2) <strong>Randomly</strong> <strong>select of one element </strong>out of an array:<br />
<code>$image = $image_array[array_rand($image_array)];</code></p>
<p>3) <strong>Pass the htaccess/htpassword</strong> authenticated user to a script:<br />
<code>$user = $_SERVER['REMOTE_USER'];</code></p>
<p>4) <strong>Debug $_GET variables</strong> by displaying the whole search string:<br />
<code>echo $_SERVER['QUERY_STRING'];</code></p>
<p>5) <strong>Read a flat file</strong> (file.txt in this example) in as an array and remove line breaks:<br />
<code>$newArray = preg_replace("#\r\n?|\n#","",file('file.txt'));</code></p>
<p>6) <strong>Scrub html output</strong>:<br />
<code>$output = strtr($output,array('&amp;'=&gt;'&amp;amp;','&lt;'=&gt;'&amp;lt;','&gt;'=&gt;'&amp;gt;'));</code></p>
<p>7) <strong>Validate</strong> the format of an <strong>email address</strong>:<br />
<code>if (!preg_match("(^[-\w\.]+@([-a-z0-9]+\.)+[a-z]{2,4}$)i", $email)) echo "Email address $email is not valid";</code></p>
<p>8 ) <strong>Validate</strong> the format of a <strong>domain name</strong>:<br />
<code>if (!preg_match("(^([-a-z0-9]+\.)+[a-z]{2,4}$)i", $domain)) echo "Domain name $domain is not valid";</code></p>
<p>9) <strong>Validate</strong> the format of the <strong>user name and verify valid MX records</strong> for the domain name (OK, so it is two lines):<br />
<code>list($username, $domaintld) = split("@", $email, 2);<br />
if (!getmxrr($domaintld, $mxrecords) OR !preg_match("(^[-\w\.]+$)", $username)) echo "Email address $email is not valid";</code></p>
<p>10) <strong>Remove</strong> <strong>one element from an array</strong> (in this example remove $image from array $image_array):<br />
<code>$image_array = array_merge(array_diff($image_array,(array)$image));</code></p>
<p>11) <strong>Randomly</strong> select of <strong>one element</strong> out of an array:<br />
<code>$image = $image_array[array_rand($image_array)];</code></p>
<p>12) <strong>Include</strong> using a <strong>full unix path</strong> while still maintaining script portability:<br />
<code>include($_SERVER['DOCUMENT_ROOT'] . '/file.inc');</code></p>
<p><strong>Note:</strong> If u found any error, report me.</p>
<input id="gwProxy" type="hidden" />
<p><!--Session data--><br />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<input id="gwProxy" type="hidden"><!--Session data--></input>
<input id="jsProxy" onclick="jsCall();" type="hidden" />
]]></content:encoded>
			<wfw:commentRss>http://vijayakumar.org/bulk-one-line-php-scripts.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
