Return to Snippet

Revision: 21953
at December 26, 2009 04:37 by level09


Initial Code
function updateCategory($vid, $term) {

      // Make sure the database has all the entries
      $parent = 0;
	
      // Is there an ID for this term already?
      $tid = db_result(db_query("SELECT tid FROM {term_data} WHERE vid=%d AND name='%s'",$vid,$term));
      if(!$tid) {
      // Create a new row in term_data for this term
      $tid = db_next_id('{term_data}_tid');
      db_query("INSERT INTO {term_data} VALUES(%d, 1, '%s', '', 0)", $tid, $term);
      db_query("INSERT INTO {term_hierarchy} VALUES(%d, %d)", $tid, $parent);
      }
      // The next term will be a child of this one
      $parent = $tid;
    
      // Now simply associate $tid with the product
      db_query('INSERT INTO {term_node} VALUES(%d, %d)', $product->nid, $tid);
      }

Initial URL
http://level09.net

Initial Description

                                

Initial Title
Create Taxonomies Programmaticallly

Initial Tags
drupal

Initial Language
PHP