<?php
class viewbrand{
    var $id;
    
    function listbrand(){
        $brand = mysql_query("SELECT * FROM brand ORDER BY id_brand");

        while ($p = mysql_fetch_array($brand)){
            $data[$i] = array(
                        'id' => $p[id_brand],
                        'nama' => $p[nama],
                        'keterangan' => $p[keterangan]
                     );
            
            $i++;
        }
        
        return($data);
        
    }
    
    function brand(){
        $brand = mysql_query("SELECT * FROM brand WHERE id_brand = $this->id");
        $p = mysql_fetch_array($brand);
        
        $data = array(
                        'id' => $p[id_brand],
                        'nama' => $p[nama],
                        'keterangan' => $p[keterangan]
                     );
        
        return($data);
        
    }
    
    function addbrand($nama,$keterangan){

        $tgl = date("d-m-Y");
        
        mysql_query("INSERT INTO brand(     nama,
                                            keterangan,
                                            dateadd,
                                            dateedit) 
                                            VALUES(
                                            '$nama',
                                            '$keterangan',
                                            STR_TO_DATE('$tgl','%d-%m-%Y'),
                                            STR_TO_DATE('$tgl','%d-%m-%Y'))");
    }
    
    function editbrand($nama,$keterangan){

        $tgl = date("d-m-Y");
        
        mysql_query("UPDATE brand SET    nama           = '$nama',
                                         brand          = '$brand',
                                         dateedit       =  STR_TO_DATE('$tgl','%d-%m-%Y')
                                         WHERE 
                                         id_brand       = $this->id");
    }
    
    function deletebrand(){
        mysql_query("DELETE FROM brand where id_brand = $this->id");
    }
}

