Showing posts from March, 2013

CakePHP: COUNT data and GROUP BY date

Goal: Count Tip Offs created per day for a month to use for graph
Problem: created field name is in datetime format: Y-m-d H:i:s
Solution: format SQL Query date: DATE_FORMAT(TipOff.created, '%Y-%m-%d')

Inside the function of controller
<?php$tipOffsMonthly=$this->TipOff->find('all', array('conditions'=>array('AND'=>array('TipOff.electric_cooperatives_id'=>AuthComponent::User('electric_cooperatives_id'), 'TipOff.created BETWEEN ? AND ?'=>array($first_day, $last_day))), 'fields'=>array("COUNT('created') as per_day", 'created'), 'group'=>array("DATE_FORMAT(TipOff.created, '%Y-%m-%d')") ));?>

Hostinger | Free Web Hosting with PHP and MySQL, Website Builder, No Ads


New generation of free hosting Forget stereotypes about free web hosting. Hostinger is different. We provide reliable and feature rich hosting with fanatic user support! Our service uptime is 99.9% - thanks to cloud computing technology we utilize.
PHP and MySQL Support We support PHP and MySQL without any restrictions. Our PHP engine comes with all features and functions enabled. You can switch to any PHP version in one click and manage databases with phpMyAdmin tool. No ads or banners on your pages No text links. No annoying pop-ups. No annoying banners. No mandated forum posting. Your web site will be 100 percent ad free forever. Software auto installer Just with a few clicks you may install Wordpress, Joomla, PrestaShop, phpBB, Drupal and may other scripts. Fully functional and professional looking web site can be setup in minutes. Easy to use website builder You can now build your site very easy. Even computer newbie can create a nice looking website with our …

CakePHP : Load Model from other Controller

In your Controller were you want to load the model.

<?php  App::import('Controller');class ReportsController extends AppController {publicfunction other_reports(){//this will load other model $this->loadModel('OtherModel');$otherModels=$this->OtherModel->find('all');$this->set('otherModels',$otherModels);}}?>