goFrendiAsgard / No-CMS

No-CMS, A CodeIgniter Based CMS Framework
299 stars 199 forks source link

How to call custom query and display same look and feel #51

Closed briangeary closed 11 years ago

briangeary commented 11 years ago

1) I need to call a custom query, such as SELECT count() AS TotalStates, (SELECT COUNT() FROM states) AS NumberStates, (TotalStates/NumStates) AS percentage FROM states WHERE CRITERIA > 7.5

2) In addition, I would like the results to display with the same look and feel as the no-cms theme.

I have tried creating my own model but to no luck.

Thanks

goFrendiAsgard commented 11 years ago

That's not the way doing that. I guess you want to make a "callback column". http://www.grocerycrud.com/documentation/options_functions/callback_column

public function states()
{
  $c = new grocery_CRUD();

  $c->set_table('states');
  $c->where('criteria >', 7.5);
  $c->set_subject('States');
  $c->columns('total_states, number_states, percentage');

  $c->callback_column('total_states',array($this,'_callback_total_states'));

  $output = $c->render();
  $this->_view_output($output);
}

public function _callback_webpage_url($value, $row)
{
  $query = $this->db->select('*')->from('states')->where('criteria >',7.5')->get();
  $row_count = $query->num_rows();
  return $row_count;
}

Add callback to number_states and percentage as well.

briangeary commented 11 years ago

Thanks for the response.. I got the sample you showed working. I should hopefully be able to get the rest as well. now i understand the callback functions ;)

goFrendiAsgard commented 11 years ago

Glad to help. Feel free to let me know if you have another problem :)