Welcome to my blogfolio where I write about web design, gaming and show off my work

Group Your Results with PHP

June 17th, 2008

Sort by first letter

While working on a personal project this evening, I wrote a small function to group a list of results by the first letter of each record.

As simple as it may be, I think it’s very effective in breaking up a long list of results and it’s very easy to implement.

First up I defined a list of names in an array, and then sorted them alphabetically.

  1. $contacts = array(‘John’, ‘Peter’, ‘Adam’, ‘Sam’, ‘Dick’, ‘Nicholas’, ‘Philip’, ‘Andrew’, ‘Thomas’, ‘Bruce’, ‘Steven’, ‘Brian’, ‘Terrence’);
  2. sort($contacts);

Next I created a function called ‘group_by_first’. Here’s my code, I’ll explain what’s going on underneath.

  1. function group_by_first($contact_name) {
  2.   global $cur_first;
  3.   $get_first = substr($contact_name, 0, 1);
  4.   if ($cur_first != $get_first) {
  5.     echo ‘<div style="width: 120px; height: 30px; background: #ccc;">’. $get_first .‘</div>’;
  6.     $cur_first = $get_first;
  7.     }
  8.   echo $contact_name . ‘<br />’;
  9.   }

Line 1: Here we name the function and add a parameter that stores the current record

Line 2: Creating a global variable named $cur_first (current first letter), which will be empty to start with

Line 3: Here I define a variable called $get_first, and retrieve the first character from the current record. For example, if we’re on ‘Bruce’ then $get_first will store ‘B’

Line 4: Comparing the current letter group we’re in with the first letter of the current record. If they don’t match, that means we’ve run out of records that begin with that letter and we’re ready to make a new group

Line 5: Echo out a div with some styling, and the first letter of the current record. The inline CSS is there purely for demonstration, please rememeber to define a class in your stylesheet!

Line 6: We’ve added a new group, so now we’ve got to tell $cur_first that we’re on the next letter in the list, which we do by assigning it the value of $get_first

Line 8: Finally, we echo out the current record

All we’ve got left to do now is to run each element of the array through our function!

  1. foreach ($contacts as $value) {
  2.   group_by_first($value);
  3.   }

And here’s a basic example of it in action.

With some better styling I think that this can be an elegant solution for breaking up your lists of records.

Bookmark and Share

What is Web 2.0?

June 13th, 2008

The term Web 2.0 has been on the tip of everyone’s tongue for a few years now, but there is still a lot of confusion about what it actually means.

The O’Reilly Media Web 2.0 conference in 2004 was the first notable use of the term, where Tim O’Reilly described it as:

Web 2.0 is the business revolution in the computer industry caused by the move to the Internet as platform, and an attempt to understand the rules for success on that new platform.

While I truly believe in the Internet as a platform (just look at how Google are dominating the online applications market), the rules for success are rather blurred.

Read more »

Bookmark and Share

Using Your Website Background as Advertising Space

June 6th, 2008

I posted an article on my company’s blog yesterday about a recent project for local steet dance company, Urban Strides. I explained how from the beggining of the project we wanted to use their background to advertise the many events and classes they run, and how we did just that with their latest event.

I believe your website background can be a fantastic advertising space, as Gamespot have just shown this morning with their stunning Lego Indiana Jones background.

I think that the background looks fantastic, and it was a clever move to incorporate it into their flash banner as well. This is something Gamespot do often, and I know many other sites, especially in the gaming and video sharing world, do the same.

Gamespot Lego Indiana Jones Background

Changing the background of your site to reflect what’s currently happening is a great idea. It keeps your site looking fresh, it can bring in revenue and you don’t compromise your content.

If you’ve seen any more examples of this strategy please leave a comment and let me know!

Bookmark and Share

Style Your Wordpress Comments

June 5th, 2008

The most important aspect of a blog is your readers. Without them, you’re only talking to yourself.

The main route of communication between you both is the comments under each post, so why not pretty them up a bit?

In this article I’ll show you the various CSS styles you need to change, and I’ll also explain how I added the custom background when I reply to comments on my own articles.

Read more »

Bookmark and Share

Adding the Wordpress Sidebar to Every Page

February 22nd, 2008

When you first install Wordpress, the default Kubrick theme doesn’t display the sidebar when you view a single post. It’s a feature many people ask for and here’s how you do it.

In your Wordpress admin interface, navigate to Presentation > Theme Editor and then select Single Post from the right menu. The ’single.php’ file will appear in the editing window.

The first change is to replace the second line:

<div id="content" class="widecolumn">

with

<div id="content" class="narrowcolumn">

Once that’s done, scroll to the bottom of the page and find the line <?php get_footer(); ?> and replace it with:

  1. <?php
  2. get_sidebar();
  3. get_footer();
  4. ?>

And that’s it! Your sidebar will now appear on every page of your Wordpress blog.

Bookmark and Share

Does Your Company Pay You to go Home?

February 19th, 2008

Mine does.

For those who have not heard of Google 20% time, a quick rundown. Google 20% was created to allow employees to focus on what they’re really passionate about. Many Google products and services were born through this, including Google Suggest and AdSense for Content.

Here at our studio we’re all for it too! I started off spending 20% of my week learning PHP, MySQL and anything else that tickled my fancy. While we definately saw how powerful a tool this could be, we recently pushed it even further.

We’re getting increasingly busy lately and as such this 20% time started to take a back seat for me. I’d feel bad if I was reading up on the latest Facebook app when there was work that I knew had to be done. I had a chat with my boss and he suggested that I work from home one afternoon a week. Again, I didn’t feel quite right taking up the offer but we decided to give it a trial run.

Wednesday afternoon rolled around and I went home, laptop in hand, ready to spend the afternoon developing my knowledge. Thursday morning I came in with a new product which several clients have already bought into! Having that space at home without the telephone going, or Outlook constantly telling me that I have more work, allowed me to be more creative and gave our company a new product to sell.

I’m thoroughly enjoying spending this time to better myself and I can’t recommend it enough!

Bookmark and Share

Web 2.0 Thoughts and Suggestions

February 18th, 2008

Note: I wrote this article almost a year ago for our company blog but I thought it was well worth posting it here as well. Hope you find it useful!

Yesterday Imre visited the Internet World exhibition in Earl’s Court, London. We attended a couple of seminars on Web 2.0 and found some very interesting ideas and suggestions.

Read more »

Bookmark and Share

I’m back!

February 18th, 2008

Wow. I can’t believe it’s been half a year since I’ve posted here.

I set a new year’s resolution to redesign and clean out my blog, and I’m almost done!

Please check back soon for my thoughts on web design and gaming.

Bookmark and Share