<?PHP
/******************************************************
    keywords class

- used to import and retreive keyword information
******************************************************/

class keywords{
    
    var 
$data = array();
    var 
$dataLookup = array();
    
    function 
keywords(){
        
$sql "SELECT * FROM `keyword` ORDER BY replace(`keyword`, '~', ''), `keyword`";
        
$results mysql_query($sql) or die(mysql_error());
        while(
$row mysql_fetch_assoc($results)){
            
$this->data[] = $row;
            
$this->dataLookup[$row['keyword']] = $row;
        }
    }
    
    function 
getId($keyword$importIfNeeded false){
        if(isset(
$this->dataLookup[$keyword])) return $this->dataLookup[$keyword]['keyword_p'];
        if(
$importIfNeeded) return $this->_import($keyword);
        return 
false;
    }
    
    function 
_import($keyword){
        
$sql "INSERT INTO `keyword` (`keyword`, `_added`) VALUES ('".$keyword."', NOW())";
        
mysql_query($sql) or die(mysql_error());
        
$newId mysql_insert_id();
        
$this->keywords();
        return 
$newId;
    }
    
}

?>