COUNT / GROUP BY with active record?

I believe you’ll want something like this: $this->db->select(‘user_id, COUNT(user_id) as total’); $this->db->group_by(‘user_id’); $this->db->order_by(‘total’, ‘desc’); $this->db->get(‘tablename’, 10); This will produce a result like | USER_ID | TOTAL | | 12 | 3 | | 15 | 2 | | 18 | 1 | UPDATE: As some pointed out in the comments the original query was summing … Read more

How to upload image in CodeIgniter?

It seems the problem is you send the form request to welcome/do_upload, and call the Welcome::do_upload() method in another one by $this->do_upload(). Hence when you call the $this->do_upload(); within your second method, the $_FILES array would be empty. And that’s why var_dump($data[‘upload_data’]); returns NULL. If you want to upload the file from welcome/second_method, send the … Read more

Using Mysql WHERE IN clause in codeigniter

You can use sub query way of codeigniter to do this for this purpose you will have to hack codeigniter. like this Go to system/database/DB_active_rec.php Remove public or protected keyword from these functions public function _compile_select($select_override = FALSE) public function _reset_select() Now subquery writing in available And now here is your query with active record … Read more

Uploading a csv into Codeigniter

I got it working by adding cbrandolino‘s suggested mimetypes to the config/mimes.php (great tip jljohnstone). So the csv property of my $mimes looks like this now: ‘csv’ => array(‘application/’, ‘text/anytext’, ‘text/plain’, ‘text/x-comma-separated-values’, ‘text/comma-separated-values’, ‘application/octet-stream’, ‘application/’, ‘application/x-csv’, ‘text/x-csv’, ‘text/csv’, ‘application/csv’, ‘application/excel’, ‘application/vnd.msexcel’)

HTTP OPTIONS error in Phil Sturgeon’s Codeigniter Restserver and Backbone.js

I encountered exactly the same problem. To solve it I have a MY_REST_Controller.php in core and all my REST API controllers use it as a base class. I simply added a constructor like this to handle OPTIONS requests. function __construct() { header(‘Access-Control-Allow-Origin: *’); header(“Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method”); header(“Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, … Read more

How to rewrite the index.php of Codeigniter on Windows Azure

You can add rewrite rules in your web.config file. Add the following to the system.webServer section: <rewrite> <rules> <rule name=”Rule” stopProcessing=”true”> <match url=”^(.*)$” ignoreCase=”false” /> <conditions> <add input=”{REQUEST_FILENAME}” matchType=”IsFile” ignoreCase=”false” negate=”true” /> <add input=”{REQUEST_FILENAME}” matchType=”IsDirectory” ignoreCase=”false” negate=”true” /> <add input=”{URL}” pattern=”^/favicon.ico$” ignoreCase=”false” negate=”true” /> </conditions> <action type=”Rewrite” url=”index.php/{R:1}” appendQueryString=”true” /> </rule> </rules> </rewrite>

Codeigniter image resize?

You shouldn’t load image_lib in foreach. Try to use code below $this->load->library(‘image_lib’); foreach($results as $row) { $config[‘image_library’] = ‘gd2’; $config[‘source_image’] = ‘/img/proizvodi/’.$row->proizvodid.’.jpg’; $config[‘create_thumb’] = TRUE; $config[‘maintain_ratio’] = TRUE; $config[‘width’] = 75; $config[‘height’] = 50; $this->image_lib->clear(); $this->image_lib->initialize($config); $this->image_lib->resize(); } If it wont work – check the upload folder permissions.