Welcome Guest, Not a member yet? Register   Sign In
Codeigniter with big database
#4

[eluser]jonez[/eluser]
Instead of doing 20 queries individually do them all as one query (group by) then delegate the response array. As CroNiX said indices will help a lot and foreign key's should be on all your join columns.

Your query should return something like this (16/12 are ex. category ID's);
Code:
1 - 16 - News - Post 1
2 - 16 - News - Post 2
3 - 16 - News - Post 3
4 - 12 - Sports - Post 1
5 - 12 - Sports - Post 2
6 - 12 - Sports - Post 3
...

Loop through it and push records into groups;
Code:
$records = $this->db->query( $sql, $params )->result_array( );
$results = array( );

foreach ( $records as $record ) {
  if ( !array_key_exists( $record[ 'cat_id' ], $results ) ) {
    $results[ $record[ 'cat_id' ] ] = array( );
  }

  $results[ $record[ 'cat_id' ][ ] = $record;
}


Messages In This Thread
Codeigniter with big database - by El Forum - 01-19-2014, 08:51 PM
Codeigniter with big database - by El Forum - 01-19-2014, 10:15 PM
Codeigniter with big database - by El Forum - 01-19-2014, 11:16 PM
Codeigniter with big database - by El Forum - 01-21-2014, 05:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB