/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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); }
URL: http://level09.net