title: codeigniter fetch mysql table with where_in + keep order of key array in result array
body: <p>I have a string with image ids (fetched from another mysql table)
  and converted to an array:</p>
  
  <pre><code>$idstring = "12, 18, 3, 392, 0, 9, 44";
  $idarray = explode(',', $idstring);
  </code></pre>
  
  <p>Based on this array of ids, I want get all the rows from my "media" mysql table.</p>
  
  <pre><code>$result = $this-&gt;db-&gt;select('*')
  -&gt;from('media')
  -&gt;where_in('id', $ids)
  -&gt;get()-&gt;result_array();
  </code></pre>
  
  <p>The problem is the <code>$result</code> array's values are in a weird order like this:</p>
  
  <pre><code>$result's order : 44, 9 ,0 ,18 ,3 ,392 ,12 ...
  </code></pre>
  
  <p>But i need them to stay like in my $id string/array order...</p>
  
  <p>I've tried 4 approaches to solve the issue so far:</p>
  
  <ol>
  <li><p>Fetch rows in a loop without <code>where_in()</code> - what creates a lot of queries - but works for now ... </p></li>
  <li><p>Reorder the <code>$result</code> array based on the order of the <code>$idstring</code> or the <code>$idarray</code>, though I could not manage to to find a working result and I don't get the point why this step is necessary at all</p></li>
  <li><p>Try to get the query itself fixed. I've heard about <code>ORDER_BY</code> and <code>FIND_IN_SET</code>, <code>$ids</code> but I could not get it into my a working codeigniter query and don't know about the performance if this is really a help</p></li>
  </ol>
  
  <p>So in conclusion, I think this should be a simple everyday task, i just want to fetch a bunch of pictures in a given order with codeigniter.</p>
  
  <p>Am I missing a simple solution here?</p>