Working with SMF

I was working upon upgradate & modification of a forum powered by SMF. My first job was to upgrade the forum from SMF 1.1.14 to SMF 2.0.1. I found no difficulties in doing the upgardate. If you are not well accomplish with SMF upgrade process then here is a good instruction for you.

My next job was to customize the board icons. I googled a mod for this purpose. It is cbi v0.5 (Custom Board Icons). I downloaded the latest version of the mod which is cbi172.zip. I tried to follow the installation process for the mod but got no result. Then I tried for the manual installation instruction for SMF version 2.0.1. But it was my bad luck as I found the modification wasn’t compatible with version 2.0.1. So I had to spent some time with the code to make it work. This is what I had done.
Continue reading ‘Working with SMF’ »

Computational Search Engine – Wolfram|Alpha

When we look for something in the web we use search engines. Like many of you my favourite SE is Google. The term googling started upon doing search using the Google. Then comes Bing. Now what do we search using SE? I asked my friends & collogues about this. Majority of the answers are almost anything. Well I also think more or less the same, but with an assumption of existence of the information on the web. This means I search for things like address of restaurant or coffee shop,  specific product review, news for certain things or may be work related information etc. I believe most of you also do the same. In simple words we search information present in the web using SE.

Now if you need to find out the some information like 30 degree C equivalent F or 8% tax upon $1200 or interest amount upon $4500 with 13.5% yearly compound interest etc. Best way is to find out pen & paper and a calculator to do the math. I found out an interesting search engine powered by computational power. Continue reading ‘Computational Search Engine – Wolfram|Alpha’ »

Advertizing hazard?

Capture Source : Nokia E51
Date : 06-30-2011 14:13 IST
Location : 22°34′ N; 88°24′ E

advertize

New biological race?

Indian currency number 2 word conversion

I had created number to word conversion function earlier. Now while working upon a web based financial management application I need to use this function once more. However I found my old function is not working properly with big numbers and also with currency amount(2 digit decimal value). So I need to change the code a little bit. Ranajit suggested me to put this a post as he didn’t find out any such good conversion code. He informed me about some PEAR class [Numbers_Words], but it provides USD as currency.

First check this working example here – CurrencyToWords, then the code is here:-
Continue reading ‘Indian currency number 2 word conversion’ »

Chart Tools by Google Code

“A picture is worth a thousand words.” To explain a set of data, the better way is create a chart. In PHP there a lot of chart designing tools/application. Today I spent some time with a charting tool provided by Google Code. I find this tool is really useful and easy to use. Like other Google codes it provides a lots of customization options. There are 2 kind of charting type supported by 2 different APIs. One produces Image chart and another produces Interactive Charts.

To explore with Google Chart API for Image chart I chose the data set of browser usages by visitors on my blog for the month of January 2011. Here is a snapshot from Awstats from my blog cPanel.

Browse usage comparison of Cohesive Web for January 2011

Here is the chart produced by the Google Chart API.

Comparison Chart produced by Google Chart

Let me explain the process I have used for drawing this chart. Continue reading ‘Chart Tools by Google Code’ »

Auto increment Value of a MySql table in PHP

In MySql database the auto increment value of a field is a very important feature that we use frequently for our projects. Value of a auto increment field is a auto generated number. This number generates when you insert a row in the table. Most of the cases we make data type of that field as integer and as primary key. In many of my projects I have used this field value as the primary ID and mapped other data stored in other tables.

In PHP a new value of this type of field can be accessed after inserting a record in the table, using the function mysql_insert_id(). But you can many such cases where you need to access this value before inserting the record. Earlier I used a technique to get that value. Execute a simple sql query to get that value. The sql is:

  1. SELECT MAX(prodId) FROM ProductTable

Where prodId is the field name with auto increment and is the ProductTable table name. Now add 1 with returned value and you will get the new value for that field. However this process may produce incorrect result if you do delete operation upon that table. Let me explain a little more.

Say currently the ProductTable contains 100 records. So the possible next record Id will be 101. Now if you delete record no. 21 or 49 or 65 or 78 you will still have the next record Id as 101. But say if you delete record 100. Logically you should get the next record Id as 100. Your sql query will give the value as 99 and adding 1 with it will produce 100. Seem no problem, right? Wrong, just insert a record and you will find the prodId for the record is 101. How this happened? MySql database stores 1 as starting value when you create the table. Now every time you insert a record the auto increment value get incremented by 1.This way it produces a unique number every time you insert a record in the table. Generally table in MySql database don’t reuse the deleted Id. As a result the above said process will not work in case deletion of record.

Continue reading ‘Auto increment Value of a MySql table in PHP’ »

SEO Correction in PEAR::Pager

Pagination is a common practice to show big volume of data. It is quite important if you are showing dynamically populated data.

For myself I mostly use PEAR::Pager to display paginated data. If you are familiar with this package then you know that you can use 2 types of pagination display, as – sliding and jumping. In case of sliding display with a common practice is to use it with constructor option append:true and urlVar:<variablename>.

Let me show an example of this kind of usage –

  1. $Params = array(
  2.           ‘itemData’ => $dataDetails,
  3.           ‘perPage’ => $ViewPerPage,
  4.           ‘append’ => true,
  5.           ‘separator’ => ‘|’,
  6.           ‘spacesBeforeSeparator’ => 1,
  7.           ‘spacesAfterSeparator’ => 1,
  8.           ‘clearIfVoid’ => false,
  9.           ‘urlVar’ => ‘page’,
  10.           ‘useSessions’ => true,
  11.           ‘closeSession’ => true,
  12.           ‘mode’  => ‘Sliding’,
  13.           ‘importQuery’ => true,
  14.           ‘linkClass’ => ‘LinkStyle’,
  15.           );
  16. $Pager = Pager::factory($Params);
  17. $DataDetailsInArray = $Pager->getPageData();
  18. $PaginationLinks = $Pager->getLinks();

Now if you print/echo the $PaginationLinks, then you will get pagination like 1 2 3 4 etc.

Now let me describe you the problem:
Say your page url is mydata.php. So mydata.php page will show the first page of paginated data. while using the pagination links you will get a page with url mydata.php?page=1. This page shows the first page of paginated data. Now you are having a page with 2 different url like mydata.php and mydata.php?page=1. In SEO this is known as duplicate content. This is not good if you are seriously deal with SEO.

Here is the correction for this. This is simple but effective.

  1. if(isset($_GET[‘page’]) && $_GET[‘page’] > 1)
  2. {
  3.    $PaginationLinks[‘all’] = str_replace(array(‘?page=1"’, ‘&amp;page=1"’), ‘"’, $PaginationLinks[‘all’]);
  4. }

Use this code section just after generating $PaginationLinks. Hope this will help you. As always comments/suggestions are welcome. But spammers please don’t waste your time. :)

PaginationSlider – a jQuery plugin

I have started using jQuery – JavaScript framework almost end of the last year. I have also used it for my last couple of projects. I find it very useful to design/develop complex type of functionality in the client-end. One of the interesting feature of jQuery is that it provides a large number of plugins designed by different developers. They are very useful too.

In my current project I need to display multiple content pages within a web page. I require to slide the page numbers so that user can view the number of pages by sliding/scrolling. I was looking for some good plugin which could satisfy my need. I have tested some of them but couldn’t find out the ideal one. So wrote the basic code for the functionality and the effect. However I wasn’t satisfied with my work as I was looking for some plugin for it. I thought it is the best time to try authoring plugin in jQuery.

It took almost 9 days to convert the code into a plugin. I gave the plugin namespace as paginationslider.

Code example:
Script section –

  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  2.    <script type="text/javascript" src="jquery.paginationslider.js"></script>
  3. <script type="text/javascript">
  4. $(document).ready(function(){
  5.    $(‘#sliderMain’).paginationslider({
  6.                                     SliderLeft:‘LeftSlide’,
  7.                                     SliderRight:‘RightSlide’
  8.                                     });
  9. });
  10. </script>

Style section –

  1. .pgSlider {
  2.   width: 80px; overflow: auto; background:#fff; margin:0 auto; position:relative; border:1px solid orange; float:left; display:inline;
  3. }
  4. .pgSlider ul {
  5.   display: block; padding: 0; margin: 0; list-style: none; position:relative;
  6. }
  7. .pgSlider ul li {
  8.   display: block; float: left; background:#E3ECF4;
  9. }
  10. .pgSlider a {
  11.   display: block; text-decoration: none; text-align:center; padding: 5px 8px; color:#1079B1; font-weight:bold; border-right:1px solid #fff;
  12. }

HTML Section –

  1. <pre class="html" name="code">
  2. <div id="paginationContainer">
  3.    <div id="LeftSlide" class="sliderArrow">&lt;&lt;</div>
  4.    <div id="sliderMain" class="pgSlider">
  5.       <ul>
  6.          <li><a href="#1">1</a></li>
  7.          <li><a href="#2">2</a></li>
  8.          <li><a href="#3">3</a></li>
  9.          <li><a href="#4">4</a></li>
  10.          <li><a href="#5">5</a></li>
  11.          <li><a href="#6">6</a></li>
  12.          <li><a href="#7">7</a></li>
  13.          <li><a href="#8">8</a></li>
  14.          <li><a href="#9">9</a></li>
  15.       </ul>
  16.    </div>
  17.    <div id="RightSlide" class="sliderArrow">&gt;&gt;</div>
  18. </div>
  19. </pre>

I will eagerly wait for your reviews on this plugin. Here you can view the demo.

Freetag PEAR DB Version

While working with tagging application my favourite is freetag by Gordon Luk. It is a comprehensive open source tagging and folksonomy code in php. The source code is also hosted in Google Code. The best feature of it is you can use this code with little modification to fit your requirement. First time I used it in advaitaashrama.org for their book store application. Currently I am using it in another website which is under development.

I am having an issue of compatibility with this code and I am writting this post for it. If you look at the code you will find that it uses the ADODB Library for database operations. In my case I am happy with PEAR::DB. Now for me to use this code I need to use 2 different database component as PEAR::DB and ADODB Library. It seems useless to me. So I decided to make the code compatiable with PEAR::DB. While working upon the compatibility modification I also made 3 changes as

  1. I have written a function as show_debug_text() which is a replacement of debug_text().
  2. I have removed the silly_list() function from my code as it was declared as deprecated.
  3. I have renamed the main class file from freetag.class.php to freetag.db.class.php

Here is the sample code for use this

  1. <php?
  2. require_once("/path-to/freetag.db.class.php");
  3. $DbObj = DB::connect($dsn, $options); //this is the database connection object using PEAR::DB
  4. $OptionArray = array(
  5.                ‘table_prefix’ => ‘mytags’,
  6.                );
  7. $TagObj = new freetag($DbObj, $OptionArray);
  8. // Use this object to call tag related functions .
  9. ?>

Here is the code modified by me.
If you use this code please let me know if you have any problem.

PHP serialization or Json

Information storage and retrieval is an important job while designing or developing an application. We all know how to store data with normal data types in database or file systems. Here I am going to discuss about storage and retrieval of data having complex type. Complex type means they are not like normal string or number or boolean values. Complex type means data structure or objects.

Think of a situation where you are working with some array. Now there may be some situations where you need to store the array and retrieve it back. If you are familiar with OOPS concept then objects are another type which you may need to store and retrieve.

Serialization is the process by which you can convert an object or data structure into a sequence of bits which can stored and retrieve back. Serialization is also known as deflating or marshalling. The opposite process (converting the serialized sequence of bits to object or data structure) is known as Deserialization or inflating or unmarshalling. Most of the important languages have their own implementation of these processes. In Java provides automatic serialization by implementing the java.io.Serializable interface. In perl there are modules like Storable or FreezeThaw. Python implements serialization through the standard library module pickle. In PHP there are two built-in functions as serialize() and unserialize() for this purpose. However as I will continue the discussion with PHP then you should be aware of the fact that – there is a difference in the implementation of serialization in PHP 4.x and PHP 5.x.

Continue reading ‘PHP serialization or Json’ »