Programming-related articles, from quick tips to tutorials on a variety of topics for webmasters and developers alike. PHP, C#, Python, Java, Flash, MySQL, MSSQL and more are covered.

A Simple Twitter Search Parser with PHP

I was recently asked to aggregate tweets based on their hashtags using PHP (no Ajax), so I decided to turn this into a small tutorial that will hopefully enable you build all sorts of XML parsers in PHP.
Read more

VirtueMart quick tip: show brand/manufacturer logo in product details

I recently had to provide a VirtueMart/Joomla solution for a customer. If you don’t know what VirtueMart is – it’s an open source ecommerce platform and it’s pretty good too.

They wanted a brand logo to be displayed in the product details, along with some other details. VirtueMart supports Manufacturer details but by default it just shows the manufacturer’s name in brackets, with a javascript pop-up window that looks pretty ugly.

Fortunately we can add the logo by using the description field of the Manufacturers details and by hacking one file.

VirtueMart with Manufacturer icon

VirtueMart with Manufacturer icon

The following is tested and works for VirtueMart 1.1.3 and 1.1.4. I haven’t tried it with newer versions.

So, open /administrator/components/com_virtuemart/html/shop.product_details.php

at around line 517, it looks like this:

if( $manufacturer_id && !empty($manufacturer_name) ) {
    $link = "$mosConfig_live_site/index2.php?page=shop.manufacturer_page&manufacturer_id=$manufacturer_id&output=lite&option=com_virtuemart&Itemid=".$Itemid;
    $text = '( '.$manufacturer_name.' )';
    $manufacturer_link .= vmPopupLink( $link, $text );

    // Avoid JavaScript on PDF Output
    if( @$_REQUEST['output'] == "pdf" )
    $manufacturer_link = "<a href="$link" target="_blank" title="$text">$text</a>";
}

replace it with:

if( $manufacturer_id && !empty($manufacturer_name) ) {
$manufacturer_link = $manufacturer_name;
  $q  = "SELECT `manufacturer_id`,`mf_name`,`mf_email`,`mf_desc`,`mf_url` FROM `#__{vm}_manufacturer` WHERE ";
  $q .= "`manufacturer_id`=$manufacturer_id";
  $db->query($q);
  if($db->next_record())
  {
  $mf_name=$db->f("mf_name");
  $mf_email=$db->f("mf_email");
  $mf_desc=$db->f("mf_desc");
  $mf_url = $db->f("mf_url");
  }
  if (!empty($mf_desc))  $manufacturer_link = "$mf_desc";
}

In the example above I’m using just the description (to show the logo) but you can use it to show other fields, just replace $mf_desc with $mf_name, $mf_email, $mf_url or a combination.

The method worked great and the product pages looked so much better, our client started building custom logos for some of the products that don’t have one using a logo creator.

Just one warning: this is an unsupported hack, so when you upgrade VM, you must reapply it.

Using MySQL to generate daily sales reports with filled gaps

This is a classic problem but I was surprised to see that there’s not a great deal of info on the web on how to do a proper daily report – one that doesn’t have any gaps when data is missing. In this post I’ll guide you through building such a report using MySQL and PHP for presentation. Obviously, you will need to adapt the code for your needs, but the concepts should be valid for a wide range of similar needs.
Read more

Javascript animated collapsible panels without any frameworks

If you need to make collapsible panels that remember their state, but don’t want to use any javascript framework, this tutorial will help you do this with no headaches – and you’ll learn some neat javascript tricks too!
Read more

Does your PHP/MySQL app speak Unicode?

I find it very annoying when I come across web apps that still can’t handle non-ASCII characters correctly. In this article, I’ll show you how, with just a few lines of code, you can “globalize” your online app. If you look at the illustration on the left, if you don’t plan for users entering words with “weird” characters, your output will look simply awful.
Read more

Generate Objects from Xml Files

Recently needed some quick method to use objects generated from an existing xml file without bothering to create an xml schema for it.
Read more

AS3 Performance Optimization

Working on a CPU-intensive app in flash is a challenging experience. It can be wonderful or frustrating, depending on your mindset.
Read more

Flash CS4 supports conditional compilation

With all the excitement about CS4 and the major features it brings (3D, the new timeline and so on), some less ‘shiny’ improvements tend to be overlooked.
Read more

Searching in all tables and columns of a database

I was forced recently to do some maintenance and bug fixing on an aging .NET-based CMS.

Most of the problems were in the SQL Server database, with lots of corrupted entries. The most frustrating thing however was that at times I didn’t even know where to find the entries. Try finding some specific strings in a database with a hundred tables, each with many columns (poorly named, obviously) and tens of thousands of records — it’s like finding the proverbial needle in the haystack.
Read more