Virtuemart Category ID to Category Name Function | 2008-03-02

Technology Blog » Web Development

The variable $category_id can be found in every Virtuemart page, but category name is not, there will be a problem to do the conditional statement for specific category since we are not intend to remember category id but category name.

Here is the function I wrote to use $category_id as a query keyword to look for its category name in database. And then return the category name value......


   1: <?php

   2: defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
   3: //---------------------------------------------------------------------
   4: //    Written by Andy Ng www.PCinvent.com www.PCinvent.com
   5: //    andy: start of function catIdToName()
   6: //    start prase category id to Name for sorting switch on the top
   7: //---------------------------------------------------------------------
   8: function catIdToName($catid) {
   9:     $db2 = new ps_DB;
  10:     $q2 = "SELECT category_name FROM #__{vm}_category WHERE category_id = $catid";
  11:     $db2->query($q2);
  12:     $catname2 =$db2->f("category_name");
  13:     return $catname2;
  14:     }
  15: //---------------------------------------------------------------------
  16: //    andy: end of function catIdToName()
  17: //---------------------------------------------------------------------
  18: ?>