Chapter 7: Improving the Dashboard
214
function getColor($id){
$data = array();
$options = array(‘id’ = > $id);
$Q = $this- > db- > getwhere(‘colors’,$options,1);
if ($Q- > num_rows() > 0){
$data = $Q- > row_array();
}
$Q- > free_result();
return $data;
}
function getAllColors(){
$data = array();
$Q = $this- > db- > get(‘colors’);
if ($Q- > num_rows() > 0){
foreach ($Q- > result_array() as $row){
$data[] = $row;
}
}
$Q- > free_result();
return $data;
}
function createColor(){
$data = array(
‘name’ = > $_POST[‘name’],
‘status’ = > $_POST[‘status’]
);
$this- > db- > insert(‘colors’, $data);
}
function updateColor(){
$data = array(
‘name’ = > $_POST[‘name’],
‘status’ = > $_POST[‘status’]
);
$this- > db- > where(‘id’, $_POST[‘id’]);
$this- > db- > update(‘colors’, $data);
}
function deleteColor($id){
$data = array(‘status’ = > ‘inactive’);
$this- > db- > where(‘id’, $id);
$this- > db- > update(‘colors’, $data);
}