Recent News

“How to add archive functionality to your PHP app”

Posted by admin on September 26th, 2007

“An archive refers to a collection of records, and also refers to the location in which these records are kept. Archives are made up of records which have been created during the course of an individual or organization’s life.” - Wikipedia.

Archive is an essential feature of a well defined blog system. If you have a blog in blogger or wordpress, you’ll get built-in archive feature there. But if you are making a blog yourself or any similar application, you might need to add this function yourself. These are some ideal example of archives:

Omar Al Zabir www.phpfour.com somewherein bangla blog

I’ve done it for one of my app and here I am telling you the time saving tip: creating an archive function in 3 easy steps.

1. Generate organized archive data: Generally, archives are created on create date of contents. Let’s say, your blogs table has a field named create_date which holds the timestamp of the post. Now, you can get your archive data in very organized format with this simple yet powerful query (it’s in MySQL):

SELECT COUNT(id) total, MONTHNAME(create_date) month, YEAR(create_date) year

FROM blogs

GROUP BY MONTH(create_date), YEAR(create_date)

ORDER BY create_date

Note that you’ll need to use where clauses if there are any condition. The output of your query should look like this:

Query to retrieve archive data The result
image image

 

2. Use the archive data: After you have retrieved the archive data, you can display them in any sidebar of your application. A sample code can be as follows:

 

 1: <h4>Older Entries</h4>
 2: <ul>
 3: <?php foreach ($archive as $month): ?>
 4: <li>
 5: <a href="<?php echo $month[’year’] . "/" . $month[‘month’] ?>">
 6: <?php echo $month[‘month’] . " " . $month[‘ year’] ."(" . $month[‘total’] .")" ?>
 7: </a>
 8: </li>
 9: <?php endforeach; ?>
 10: </ul>

So, what’s done here? Well, it displays the archive sets with an appropriate link. Note that the link are created in “clean URL” style, i.e. yourdomain.com/2007/july – if you are using an MVC framework like CodeIgniter or CakePHP, you may find it easy to integrate. You can of course create it in the old style, by changing the above code in this way:

 1: <li>
 2: <a href="blog.php?year=<?php echo $month[‘year’] ?>&month=<?php echo $month[‘month’] ?>>
 3: <?php echo $month[month‘] . " " . $month[’ year ‘] ."(" . $month[’total‘] .")" ?>
 4: </a>
 5: </li>

3. Display related posts: And now you’ll need to handle the fetching of appropriate posts based on the passed archive information (year and month), but that’s something that only you can figure out, as I don’t know what you have in there.

Happy Blogging…Happy Archiving :)

Hello World!

Posted by admin on September 24th, 2007

Hellow World! Now I am here…. at ajaXray.

I have been blogging on wordpress for a short time as http://php4bd.wordpress.com/. Though it’s a nice experience, I am facing some limitations there. Moreover, I have been thinking for a domain to share, test and explore my works and experience on an unique web identity. As a result, I get the domain ajaXray.

Behind the name : The name “ajaXray” comes from 2 words.

  1. ajax: AJAX, is a web development technique used for creating interactive web applications. This is the current crazes of web technologies.
  2. X-ray: X-rays (or Röntgen rays) are a form of electromagnetic radiation with a wavelength in the range of 10 to 0.01 nanometers. generally, its known to us for it’s power of scanning. I choose the word after ajax to express the interest of exploring the web technologies in such a scanning depth.

And the last thing… this domain+hosting is gifted by my (30%)boss, (30%)teacher and (40%) friend Emran Hasan aka phpfour.today is his birthday. HAPPY BIRTHDAY TO PHPFOUR.

Recent Comments | Recent Posts


designed by: Website Builder | Coded by: Blog Directory | Provided by: Wedding photojournalism chicago
bottom