<?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/"
	>

<channel>
	<title>All PHP Script</title>
	<atom:link href="http://www.allphpscript.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.allphpscript.com</link>
	<description>SELECT * FROM brain WHERE body="slacker" AND mind="procrastinator"</description>
	<pubDate>Wed, 09 Dec 2009 13:06:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Validate Singapore NRIC</title>
		<link>http://www.allphpscript.com/2009/12/09/validate-singapore-nric/</link>
		<comments>http://www.allphpscript.com/2009/12/09/validate-singapore-nric/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 13:06:59 +0000</pubDate>
		<dc:creator>Lu Yee</dc:creator>
		
		<category><![CDATA[Javascripts]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.allphpscript.com/?p=59</guid>
		<description><![CDATA[This is a javascript function to validate NRIC for Singapore residents, as well as for those holding work permit, S pass, EP and PR.
function validate(nric) {
 if (nric.length != 9) {
 return false;
 }
 
 var icArray = new Array(9);
 for(i = 0; i &#60; 9; i++) {
 icArray[i] = nric.charAt(i);
 }
 
 icArray[1] *= [...]]]></description>
			<content:encoded><![CDATA[<p>This is a javascript function to validate NRIC for Singapore residents, as well as for those holding work permit, S pass, EP and PR.</p>
<p>function validate(nric) {</p>
<p><span> </span>if (nric.length != 9) {</p>
<p><span> </span>return false;</p>
<p><span> </span>}</p>
<p><span> </span></p>
<p><span> </span>var icArray = new Array(9);</p>
<p><span> </span>for(i = 0; i &lt; 9; i++) {</p>
<p><span> </span>icArray[i] = nric.charAt(i);</p>
<p><span> </span>}</p>
<p><span> </span></p>
<p><span> </span>icArray[1] *= 2;</p>
<p><span> </span>icArray[2] *= 7;</p>
<p><span> </span>icArray[3] *= 6;</p>
<p><span> </span>icArray[4] *= 5;</p>
<p><span> </span>icArray[5] *= 4;</p>
<p><span> </span>icArray[6] *= 3;</p>
<p><span> </span>icArray[7] *= 2;</p>
<p><span> </span></p>
<p><span> </span>var weight = 0;</p>
<p><span> </span>for(i = 1; i &lt; 8; i++) {</p>
<p><span> </span>weight += parseInt(icArray[i]);</p>
<p><span> </span>}</p>
<p><span> </span></p>
<p><span> </span>var offset=(icArray[0]==&#8221;T&#8221;||icArray[0]==&#8221;G&#8221;)?4:0;</p>
<p><span> </span>var temp=(offset+weight)%11;</p>
<p><span> </span></p>
<p><span> </span>var st=Array(&#8221;J&#8221;,&#8221;Z&#8221;,&#8221;I&#8221;,&#8221;H&#8221;,&#8221;G&#8221;,&#8221;F&#8221;,&#8221;E&#8221;,&#8221;D&#8221;,&#8221;C&#8221;,&#8221;B&#8221;,&#8221;A&#8221;);</p>
<p><span> </span>var fg=Array(&#8221;X&#8221;,&#8221;W&#8221;,&#8221;U&#8221;,&#8221;T&#8221;,&#8221;R&#8221;,&#8221;Q&#8221;,&#8221;P&#8221;,&#8221;N&#8221;,&#8221;M&#8221;,&#8221;L&#8221;,&#8221;K&#8221;);</p>
<p><span> </span>var theAlpha;</p>
<p><span> </span>if     (icArray[0]==&#8221;S&#8221;||icArray[0]==&#8221;T&#8221;) { theAlpha=st[temp]; }</p>
<p><span> </span>else if(icArray[0]==&#8221;F&#8221;||icArray[0]==&#8221;G&#8221;) { theAlpha=fg[temp]; }</p>
<p><span> </span></p>
<p><span> </span>if (icArray[8] != theAlpha) {</p>
<p><span> </span>return false;</p>
<p><span> </span>}</p>
<p><span> </span>else {</p>
<p><span> </span>return true;</p>
<p><span> </span>}</p>
<p>}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.allphpscript.com/2009/12/09/validate-singapore-nric/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Check if your page is being iframed</title>
		<link>http://www.allphpscript.com/2009/11/05/check-if-your-page-is-being-iframed/</link>
		<comments>http://www.allphpscript.com/2009/11/05/check-if-your-page-is-being-iframed/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 04:40:23 +0000</pubDate>
		<dc:creator>Lu Yee</dc:creator>
		
		<category><![CDATA[Javascripts]]></category>

		<guid isPermaLink="false">http://www.allphpscript.com/2009/11/05/check-if-your-page-is-being-iframed/</guid>
		<description><![CDATA[if (window.top !== window.self) {
window.top.location.href = window.self.location.href; }
]]></description>
			<content:encoded><![CDATA[<p>if (window.top !== window.self) {</p>
<p>window.top.location.href = window.self.location.href; }</p>
]]></content:encoded>
			<wfw:commentRss>http://www.allphpscript.com/2009/11/05/check-if-your-page-is-being-iframed/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Get YouTube video and thumbnail</title>
		<link>http://www.allphpscript.com/2009/10/08/get-youtube-video-thumbnail/</link>
		<comments>http://www.allphpscript.com/2009/10/08/get-youtube-video-thumbnail/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 04:12:58 +0000</pubDate>
		<dc:creator>Lu Yee</dc:creator>
		
		<category><![CDATA[PHP Scripts]]></category>

		<guid isPermaLink="false">http://www.allphpscript.com/?p=57</guid>
		<description><![CDATA[I was working on a project the other day, which needs to buy different videos from different users in YouTube. Thus I do not want to use YouTub API as I need something simpler, and I do not need the feeds from the user.
I found this script which is able to convert the URL to [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on a project the other day, which needs to buy different videos from different users in YouTube. Thus I do not want to use YouTub API as I need something simpler, and I do not need the feeds from the user.</p>
<p>I found this script which is able to convert the URL to embedded video, and get the youtube thumbnail as well. All these are do able without using any YouTube API.</p>
<p>First, parse in the YouTube URL , which I assign the variable as $url.</p>
<p>Copy and paste the script below and change the width and height  accordingly.</p>
<p>$vidparser = parse_url($url);</p>
<p>parse_str($vidparser[query], $query);</p>
<p>$vidid = ($query['v']);</p>
<p><span> </span>$width=&#8221;550&#8243;; $height=&#8221;350&#8243;;</p>
<p><span> </span>$content = &#8220;&lt;div align=\&#8221;center\&#8221;&gt;&lt;object width=\&#8221;".$width.&#8221;\&#8221; height=\&#8221;".$height.&#8221;\&#8221;&gt;&lt;param name=\&#8221;movie\&#8221; value=\&#8221;http://www.youtube.com/v/&#8221;.$vidid.&#8221;&amp;hl=en&amp;fs=1&amp;rel=0\&#8221;&gt;&lt;/param&gt;&lt;param name=\&#8221;allowFullScreen\&#8221; value=\&#8221;true\&#8221;&gt;&lt;/param&gt;&lt;embed src=\&#8221;http://www.youtube.com/v/&#8221;.$vidid.&#8221;&amp;hl=en&amp;fs=1&amp;rel=0\&#8221; type=\&#8221;application/x-shockwave-flash\&#8221; allowfullscreen=\&#8221;true\&#8221; width=\&#8221;".$width.&#8221;\&#8221; height=\&#8221;".$height.&#8221;\&#8221;&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&#8221;;</p>
<p>echo $content;</p>
<p>To get the YouTube thumbnail, use the same method to apply to the line of code below.</p>
<div>
<div><span> </span>&lt;img src=&#8221;http://img.youtube.com/vi/&lt;?php echo $vidid; ?&gt;/2.jpg&#8221; width=&#8221;149&#8243; height=&#8221;97&#8243; border=&#8221;0&#8243; /&gt;</div>
</div>
<div></div>
<div>That&#8217;s it!</div>
]]></content:encoded>
			<wfw:commentRss>http://www.allphpscript.com/2009/10/08/get-youtube-video-thumbnail/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Jquery get Checkbox values</title>
		<link>http://www.allphpscript.com/2009/10/07/jquery-get-checkbox-values/</link>
		<comments>http://www.allphpscript.com/2009/10/07/jquery-get-checkbox-values/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 07:00:38 +0000</pubDate>
		<dc:creator>Lu Yee</dc:creator>
		
		<category><![CDATA[Javascripts]]></category>

		<guid isPermaLink="false">http://www.allphpscript.com/?p=55</guid>
		<description><![CDATA[To check a checkbox , use :-
$(&#8217;.mybox&#8217;).attr(&#8217;checked&#8217;,true) or $(&#8221;form #mycheckbox&#8221;).attr(&#8217;checked&#8217;, true)
To uncheck your checkbox :-
$(&#8217;.mybox&#8217;).removeAttr(&#8217;checked&#8217;)
To check all checkboxes :-
$(&#8221;.mybox&#8221;).each(function(){
$(&#8221;#mybox&#8221;).click()
});
To check if checkbox is checked :-

if($(&#8221;#mybox&#8221;).is(&#8217;:checked&#8217;)==true) { //do something }
]]></description>
			<content:encoded><![CDATA[<p>To check a checkbox , use :-</p>
<p>$(&#8217;.mybox&#8217;).attr(&#8217;checked&#8217;,true) or $(&#8221;form #mycheckbox&#8221;).attr(&#8217;checked&#8217;, true)</p>
<p>To uncheck your checkbox :-</p>
<p>$(&#8217;.mybox&#8217;).removeAttr(&#8217;checked&#8217;)</p>
<p>To check all checkboxes :-</p>
<p>$(&#8221;.mybox&#8221;).each(function(){</p>
<p>$(&#8221;#mybox&#8221;).click()</p>
<p>});</p>
<div>To check if checkbox is checked :-</div>
<div></div>
<div>if($(&#8221;#mybox&#8221;).is(&#8217;:checked&#8217;)==true) { //do something }</div>
]]></content:encoded>
			<wfw:commentRss>http://www.allphpscript.com/2009/10/07/jquery-get-checkbox-values/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JQuery get radio button value</title>
		<link>http://www.allphpscript.com/2009/10/07/jquery-get-radio-button-value/</link>
		<comments>http://www.allphpscript.com/2009/10/07/jquery-get-radio-button-value/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 06:51:27 +0000</pubDate>
		<dc:creator>Lu Yee</dc:creator>
		
		<category><![CDATA[Javascripts]]></category>

		<guid isPermaLink="false">http://www.allphpscript.com/?p=52</guid>
		<description><![CDATA[For this post, I will just go short and sweet. Seems easy , but lots of people looking for this solution.
var media_type = $(&#8221;input[@name=media_type]:checked&#8221;).val();
Note :@name=radio_button_id
Here&#8217;s the sample HTML
&#60;tr&#62;
&#60;td class=&#8221;form_content_white_text&#8221; valign=&#8221;top&#8221;&#62;&#60;div align=&#8221;right&#8221;&#62;Media Type: &#60;/div&#62;&#60;/td&#62;
&#60;td valign=&#8221;top&#8221; class=&#8221;form_content_white_text&#8221;&#62;
 &#60;input name=&#8221;media_type&#8221; type=&#8221;radio&#8221; id=&#8221;media_type&#8221; value=&#8221;photo&#8221; checked /&#62;Photo
 &#60;input name=&#8221;media_type&#8221; type=&#8221;radio&#8221; id=&#8221;media_type&#8221; value=&#8221;video&#8221; /&#62;Video
 &#60;/td&#62;
&#60;/tr&#62;
]]></description>
			<content:encoded><![CDATA[<p>For this post, I will just go short and sweet. Seems easy , but lots of people looking for this solution.</p>
<p>var media_type = $(&#8221;input[@name=media_type]:checked&#8221;).val();</p>
<p>Note :@name=radio_button_id</p>
<p>Here&#8217;s the sample HTML</p>
<p>&lt;tr&gt;</p>
<p>&lt;td class=&#8221;form_content_white_text&#8221; valign=&#8221;top&#8221;&gt;&lt;div align=&#8221;right&#8221;&gt;Media Type: &lt;/div&gt;&lt;/td&gt;</p>
<p>&lt;td valign=&#8221;top&#8221; class=&#8221;form_content_white_text&#8221;&gt;</p>
<p><span> </span>&lt;input name=&#8221;media_type&#8221; type=&#8221;radio&#8221; id=&#8221;media_type&#8221; value=&#8221;photo&#8221; checked /&gt;Photo</p>
<p><span> </span>&lt;input name=&#8221;media_type&#8221; type=&#8221;radio&#8221; id=&#8221;media_type&#8221; value=&#8221;video&#8221; /&gt;Video</p>
<p><span> </span>&lt;/td&gt;</p>
<p>&lt;/tr&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.allphpscript.com/2009/10/07/jquery-get-radio-button-value/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Script to FTP file</title>
		<link>http://www.allphpscript.com/2009/05/14/script-to-ftp-file/</link>
		<comments>http://www.allphpscript.com/2009/05/14/script-to-ftp-file/#comments</comments>
		<pubDate>Thu, 14 May 2009 13:37:25 +0000</pubDate>
		<dc:creator>Lu Yee</dc:creator>
		
		<category><![CDATA[PHP Scripts]]></category>

		<category><![CDATA[ftp]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.allphpscript.com/?p=44</guid>
		<description><![CDATA[I was asked to write a script to auto FTP a file up onto a server atÂ  a particular time everyday.
Writing the script to FTP file onto server is simple, and the auto upload will have to be set in the cron job.
Here is the script to FTP file. Basically what this script does is [...]]]></description>
			<content:encoded><![CDATA[<p>I was asked to write a script to auto FTP a file up onto a server atÂ  a particular time everyday.</p>
<p>Writing the script to FTP file onto server is simple, and the auto upload will have to be set in the cron job.</p>
<p>Here is the script to FTP file. Basically what this script does is query data from database, export into CSV file, and then FTP onto the server.</p>
<p>&lt;?php</p>
<p>$host = &#8220;localhost&#8221;; //database location<br />
$user = &#8220;root&#8221;; //database username<br />
$pass = &#8220;&#8221;; //database password<br />
$db_name = &#8220;ftp-upload&#8221;; //database name</p>
<p>//database connection<br />
$link = mysql_connect($host, $user, $pass);<br />
mysql_select_db($db_name);<br />
//set the file to be writable.<br />
//you may rename the file accordingly, or a unique file name which is auto generated</p>
<p>$fp = fopen(&#8217;exportfile.csv&#8217;, &#8220;w&#8221;);</p>
<p>//modify this query as you like<br />
$res = mysql_query($cmd=&#8221;SELECT * FROM form&#8217;&#8221;);</p>
<p>// fetch a row and write the column names out to the file</p>
<p>$row = mysql_fetch_assoc($res);</p>
<p>//if there is no record, the file will still be generated but there&#8217;s no record available<br />
if($row&gt;0) {</p>
<p>$line = &#8220;&#8221;;<br />
$comma = &#8220;&#8221;;<br />
foreach($row as $name =&gt; $value) {<br />
$line .= $comma . &#8216;&#8221;&#8216; . str_replace(&#8217;&#8221;&#8216;, &#8216;&#8221;"&#8216;, $name) . &#8216;&#8221;&#8216;;<br />
$comma = &#8220;,&#8221;;<br />
}<br />
$line .= &#8220;\n&#8221;;<br />
fputs($fp, $line);</p>
<p>// remove the result pointer back to the start<br />
mysql_data_seek($res, 0);</p>
<p>// and loop through the actual data<br />
while($row = mysql_fetch_assoc($res)) {</p>
<p>$line = &#8220;&#8221;;<br />
$comma = &#8220;&#8221;;<br />
foreach($row as $value) {<br />
$value=stripslashes($value);<br />
$line .= $comma . &#8216;&#8221;&#8216; . str_replace(&#8217;&#8221;&#8216;, &#8216;&#8221;"&#8216;, $value) . &#8216;&#8221;&#8216;;<br />
$comma = &#8220;,&#8221;;<br />
}<br />
$line .= &#8220;\n&#8221;;<br />
fputs($fp, $line);</p>
<p>}<br />
} //close for if $row&gt;0<br />
fclose($fp);</p>
<p>$server=&#8221;;<br />
$ftp_user_name=&#8221;;<br />
$ftp_user_pass=&#8221;;<br />
$connection = ftp_connect($server);</p>
<p>$login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);</p>
<p>if (!$connection || !$login) { die(&#8217;Connection attempt failed!&#8217;); }</p>
<p>$upload = ftp_put($connection, &#8216;upload-ftp.csv&#8217;, &#8216;upload-ftp&#8217;.csv&#8217;, FTP_BINARY);</p>
<p>if (!$upload) { echo &#8216;FTP upload failed!&#8217;; }</p>
<p>ftp_close($connection);</p>
<p>?&gt;</p>
<p>Hope this simple script will be useful to you! Set a time to run this script in your cron job, and the file will be executed at a particular time to FTP over the file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.allphpscript.com/2009/05/14/script-to-ftp-file/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MySQL SELECT range between 2 alphabets</title>
		<link>http://www.allphpscript.com/2009/01/10/mysql-select-rang/</link>
		<comments>http://www.allphpscript.com/2009/01/10/mysql-select-rang/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 03:12:57 +0000</pubDate>
		<dc:creator>Lu Yee</dc:creator>
		
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.allphpscript.com/?p=34</guid>
		<description><![CDATA[There are times we need to query from database where the record is from &#8216;A&#8217; to &#8216;M&#8217;, or from &#8216;G&#8217; to &#8216;L&#8217; or from &#8216;T&#8217; to &#8216;Z&#8217; or from.. well, you understand what I mean. To select a record range between 2 alphabets ,we can have a query like this :
$tenant_query=mysql_query(&#8221;SELECT t.*, c.* FROM tenant [...]]]></description>
			<content:encoded><![CDATA[<p>There are times we need to query from database where the record is from &#8216;A&#8217; to &#8216;M&#8217;, or from &#8216;G&#8217; to &#8216;L&#8217; or from &#8216;T&#8217; to &#8216;Z&#8217; or from.. well, you understand what I mean. To select a record range between 2 alphabets ,we can have a query like this :</p>
<p>$tenant_query=mysql_query(&#8221;SELECT t.*, c.* FROM tenant t, category c WHERE t.category__id=c.category_id AND LEFT(t.tenant_name, 1) BETWEEN &#8216;A&#8217; AND &#8216;G&#8217; ORDER BY tenant_name ASC&#8221;) or die(mysql_error());</p>
<p>The magic syntax isÂ  LEFT(fieldname, 1)Â  BETWEEN &#8216;A&#8217; AND &#8216;G&#8217;Â  . Change the range according to how you would like it to be. LEFT(fieldname,1) meaning taking the<em> first alphabet</em> from <em>fieldname</em> , from the <em>LEFT</em>Â Â </p>
<p>And that&#8217;s it!! You are now able to query records starting from certain alphabet to certain alphabet. Peanut! <img src='http://www.allphpscript.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.allphpscript.com/2009/01/10/mysql-select-rang/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Check if mysql result is empty</title>
		<link>http://www.allphpscript.com/2009/01/10/check-if-mysql-result-is-empty/</link>
		<comments>http://www.allphpscript.com/2009/01/10/check-if-mysql-result-is-empty/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 02:35:16 +0000</pubDate>
		<dc:creator>Lu Yee</dc:creator>
		
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.allphpscript.com/?p=30</guid>
		<description><![CDATA[The right method (in my opinion) to check whether the mysql_fetch_array is empty is to count the number of rows :-
Example :Â $tenant_query=mysql_query(&#8221;SELECT t.*, c.* FROM tenant t, category c WHERE t.category__id=c.category_id ORDER BY category_name ASC&#8221;) or die(mysql_error());
After the query, we shall
&#60;?phpÂ  if(mysql_num_rows($tenant_query) == 0) { Â ?&#62;
Â &#60;tr&#62;&#60;td colspan=&#8221;4&#8243;&#62;There is no tenant in this category&#60;/td&#62;&#60;/tr&#62;
Â &#60;?php } ?&#62;
As [...]]]></description>
			<content:encoded><![CDATA[<p>The right method (in my opinion) to check whether the mysql_fetch_array is empty is to count the number of rows :-</p>
<p>Example :Â $tenant_query=mysql_query(&#8221;SELECT t.*, c.* FROM tenant t, category c WHERE t.category__id=c.category_id ORDER BY category_name ASC&#8221;) or die(mysql_error());</p>
<p>After the query, we shall</p>
<p>&lt;?phpÂ  if(mysql_num_rows($tenant_query) == 0) { Â ?&gt;<br />
Â &lt;tr&gt;&lt;td colspan=&#8221;4&#8243;&gt;There is no tenant in this category&lt;/td&gt;&lt;/tr&gt;<br />
Â &lt;?php } ?&gt;</p>
<p>As you can see, we use mysql_num_rows to check. If mysql_num_rows returns 0, means there is no record from the query.</p>
<p>If there is record, then we will fetch array from the query,</p>
<p>&lt;?php while($tenant=mysql_fetch_array($tenant_query)) {Â  ?&gt;</p>
<p>That&#8217;s all, continue the rest of the coding on what you have to do!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.allphpscript.com/2009/01/10/check-if-mysql-result-is-empty/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Page Pagination</title>
		<link>http://www.allphpscript.com/2009/01/08/page-pagination/</link>
		<comments>http://www.allphpscript.com/2009/01/08/page-pagination/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 09:42:34 +0000</pubDate>
		<dc:creator>Lu Yee</dc:creator>
		
		<category><![CDATA[CSS]]></category>

		<category><![CDATA[HTML]]></category>

		<category><![CDATA[Javascripts]]></category>

		<category><![CDATA[PHP Scripts]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.allphpscript.com/?p=27</guid>
		<description><![CDATA[This is an example of how to do page pagination usingÂ ajax.Â It enables us to paginate the page without refreshing the whole page.Â I found this code somewhere else and I find it useful and easy to integrate into websites. Plus we are able toÂ  modify the css andÂ layoutÂ easily.
First of all, we will need to put include [...]]]></description>
			<content:encoded><![CDATA[<p>This is an example of how to do page pagination usingÂ ajax.Â It enables us to paginate the page without refreshing the whole page.Â I found this code somewhere else and I find it useful and easy to integrate into websites. Plus we are able toÂ  modify the css andÂ layoutÂ easily.</p>
<p>First of all, we will need to put include the javascript.</p>
<p>&lt;script type=&#8221;text/javascript&#8221; src=&#8221;js/virtualpaginate.js&#8221;&gt;&lt;/script&gt;</p>
<p>You may download the javascript file from <a href="http://www.allphpscript.com/dl/virtualpaginate.js">http://www.allphpscript.com/dl/virtualpaginate.js</a></p>
<p>Next, define the maximum number of records per page.Â Â <br />
Â $max=10;</p>
<p>Then query the total number of records. For example, mine is to query the total number of customers :</p>
<p>$total_cust=mysql_query(&#8221;SELECT c.*, co.* FROM customer c, company co WHERE c.company__id=co.company_id ORDER BY co.company_name ASC&#8221;);<br />
$total =mysql_num_rows($total_cust);</p>
<p>$total_pages = floor($total/$max);</p>
<p>Â for ($i=0; $i&lt;=$total_pages; $i++) {<br />
Â $start = $max * $i;<br />
Â $cust2=mysql_query($cmd=&#8221;SELECT c.*, co.* FROM customer c, company co WHERE c.company__id=co.company_id ORDER BY co.company_name LIMIT $start, $max &#8220;);</p>
<p>Now we create the header of the table :</p>
<p>&lt;div class=&#8221;virtualpage&#8221;&gt;<br />
&lt;div id=&#8221;container&#8221;&gt;<br />
&lt;div class=&#8221;col_01&#8243;&gt;&lt;div class=&#8221;header&#8221;&gt;#&lt;/div&gt;&lt;/div&gt;<br />
&lt;div class=&#8221;col_02&#8243;&gt;&lt;div class=&#8221;header&#8221;&gt;&lt;a href=&#8221;list-customers.php?sort=c.customer_name&amp;order=&lt;?=$direction; ?&gt;&#8221;&gt;Name&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;<br />
&lt;div class=&#8221;col_03&#8243;&gt;&lt;div class=&#8221;header&#8221;&gt;&lt;a href=&#8221;list-customers.php?sort=co.company_name&amp;order=&lt;?=$direction; ?&gt;&#8221;&gt;Company&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;<br />
&lt;div class=&#8221;col_04&#8243;&gt;&lt;div class=&#8221;header&#8221;&gt;&lt;a href=&#8221;list-customers.php?sort=c.customer_email&amp;order=&lt;?=$direction; ?&gt;&#8221;&gt;Email&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;<br />
&lt;div class=&#8221;col_05&#8243;&gt;&lt;div class=&#8221;header&#8221;&gt;&lt;a href=&#8221;list-customers.php?sort=c.customer_mobile&amp;order=&lt;?=$direction; ?&gt;&#8221;&gt;Mobile&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;<br />
&lt;/div&gt;</p>
<p>Next we pull out each records from the query :</p>
<p>&lt;?phpÂ  while($cust3=mysql_fetch_array($cust2)) {Â Â  ?&gt;</p>
<p>&lt;div id=&#8221;container&#8221;&gt;<br />
&lt;div class=&#8221;col_01&#8243;&gt;&lt;div id=&#8221;body_content&#8221;&gt;&lt;?php echo $k; ?&gt;&lt;/div&gt;&lt;/div&gt;<br />
&lt;div class=&#8221;col_02&#8243;&gt;&lt;div id=&#8221;body_content&#8221;&gt;&lt;?php echo $cust3["customer_name"]; ?&gt;&lt;/div&gt;&lt;/div&gt;<br />
&lt;div class=&#8221;col_03&#8243;&gt;&lt;div id=&#8221;body_content&#8221;&gt;&lt;?php echo $cust3["company_name"]; ?&gt;&lt;/div&gt;&lt;/div&gt;<br />
&lt;div class=&#8221;col_04&#8243;&gt;&lt;div id=&#8221;body_content&#8221;&gt;&lt;?php echo $cust3["customer_email"]; ?&gt;&lt;/div&gt;&lt;/div&gt;<br />
&lt;div class=&#8221;col_05&#8243;&gt;&lt;div id=&#8221;body_content&#8221;&gt;&lt;?php echo $cust3["customer_mobile"]; ?&gt;&lt;/div&gt;&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;?php }Â  ?&gt;<br />
&lt;/div&gt; &lt;!&#8211; close the virtualpage div &#8211;&gt;<br />
&lt;?php } ?&gt;</p>
<p>Call the class to create the pagination</p>
<p>&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
var gallery=new virtualpaginate(&#8221;virtualpage&#8221;, 1)<br />
gallery.buildpagination(&#8221;gallerypaginate&#8221;)<br />
&lt;/script&gt;</p>
<p>Tada!!! You have your pagination now. Opss it looks extremely horrible. Forgot the CSS</p>
<p>Here you go :</p>
<p>&lt;style type=&#8221;text/css&#8221;&gt;</p>
<p>.virtualpage, .virtualpage2, .virtualpage3{<br />
/*hide the broken up pieces of contents until script is called. Remove if desired*/<br />
display: none;<br />
}</p>
<p>.paginationstyle{<br />
width: 350px;<br />
text-align: center;<br />
padding: 2px 0;<br />
margin: 10px 0;<br />
}</p>
<p>.paginationstyle select{<br />
border: 1px solid navy;<br />
margin: 0 15px;<br />
}</p>
<p>.paginationstyle a{</p>
<p>padding: 0 5px;<br />
text-decoration: none;<br />
border: 1px solid black;<br />
color: navy;<br />
background-color: white;<br />
}</p>
<p>.paginationstyle a:hover, .paginationstyle a.selected{<br />
color: #000;<br />
background-color: #FEE496;<br />
}</p>
<p>.paginationstyle a.imglinks{<br />
border: 0;<br />
padding: 0;<br />
}</p>
<p>.paginationstyle a.imglinks img{<br />
vertical-align: bottom;<br />
border: 0;<br />
}</p>
<p>.paginationstyle a.imglinks a:hover{<br />
background: none;<br />
}</p>
<p>.paginationstyle .flatview a:hover, .paginationstyle .flatview a.selected{</p>
<p>color: #000;<br />
background-color: yellow;<br />
}<br />
#container {<br />
Â Â Â  display: table;<br />
Â width:750px;<br />
Â Â Â  }<br />
Â <br />
.col_01 {<br />
Â float: left;<br />
Â width: 20px;<br />
Â height:30px;<br />
}<br />
.col_02 {<br />
Â float: left;<br />
Â width: 150px;<br />
Â margin-left: 7px;<br />
}</p>
<p>.col_03 {<br />
Â float: left;<br />
Â width: 200px;<br />
}<br />
.col_04 {<br />
Â float: left;<br />
Â width: 200px;<br />
Â margin-left: 7px;<br />
}<br />
.col_05 {<br />
Â float: right;<br />
Â width: 80px;</p>
<p>}</p>
<p>.header {<br />
Â font-weight: bold;<br />
}</p>
<p>&lt;/style&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.allphpscript.com/2009/01/08/page-pagination/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Javascript Delete Confirmation</title>
		<link>http://www.allphpscript.com/2008/12/23/javascript-delete-confirmation/</link>
		<comments>http://www.allphpscript.com/2008/12/23/javascript-delete-confirmation/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 03:30:28 +0000</pubDate>
		<dc:creator>Lu Yee</dc:creator>
		
		<category><![CDATA[Javascripts]]></category>

		<category><![CDATA[PHP Scripts]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.allphpscript.com/?p=24</guid>
		<description><![CDATA[A very simple script to do deletion with PHP and a prompt confirmation using javascript.
Of course, you can have a server side confirmation using PHP as well.
I have a list of records in a table, and each row there is a Delete link. Upon clicking on the link, user will be prompted to confirm the [...]]]></description>
			<content:encoded><![CDATA[<p>A very simple script to do deletion with PHP and a prompt confirmation using javascript.</p>
<p>Of course, you can have a server side confirmation using PHP as well.</p>
<p>I have a list of records in a table, and each row there is a Delete link. Upon clicking on the link, user will be prompted to confirm the deletion.</p>
<p>&lt;a href=&#8221;list-tenants.php?del=1&amp;tenant_id=&lt;?php echo $tenant["tenant_id"]; ?&gt;&#8221; onClick=&#8221;return confirmdelete();&#8221;&gt;Delete&lt;/a&gt;</p>
<p>On the javascript, put in this code :</p>
<p>&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
function confirmdelete() {<br />
return confirm(&#8217;Are you sure you want to delete this record?&#8217;);<br />
}<br />
&lt;/script&gt;</p>
<p>If user clicks ok, in the page we use PHP to check the GET variable being passed over.</p>
<p>&lt;?php<br />
if($_GET["del"]==1) {<br />
$tenantid=$_GET["tenant_id"];<br />
$delete_sql = &#8220;DELETE from tenant WHERE tenant_id=$tenantid&#8221;;<br />
$delete = mysql_query($delete_sql) or die(mysql_error());</p>
<p>}<br />
?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.allphpscript.com/2008/12/23/javascript-delete-confirmation/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
