Professional CodeIgniter

(singke) #1

Chapter 7: Improving the Dashboard


222


Without belaboring the obvious, here are all the MSizes model functions you will need. Again, nothing
should strike you as out of the ordinary here.

function getSize($id){
$data = array();
$options = array(‘id’ = > $id);
$Q = $this- > db- > getwhere(‘sizes’,$options,1);
if ($Q- > num_rows() > 0){
$data = $Q- > row_array();
}

$Q- > free_result();
return $data;
}

function getAllSizes(){
$data = array();
$Q = $this- > db- > get(‘sizes’);
if ($Q- > num_rows() > 0){
foreach ($Q- > result_array() as $row){
$data[] = $row;
}
}
$Q- > free_result();
return $data;
}

function getActiveSizes(){
$data = array();
$this- > db- > select(‘id,name’);
$this- > db- > where(‘status’,’active’);
$Q = $this- > db- > get(‘sizes’);
if ($Q- > num_rows() > 0){
foreach ($Q- > result_array() as $row){
$data[$row[‘id’]] = $row[‘name’];
}
}
$Q- > free_result();
return $data;
}

function createSize(){
$data = array(
‘name’ = > $_POST[‘name’],
‘status’ = > $_POST[‘status’]
);

$this- > db- > insert(‘sizes’, $data);
}
Free download pdf