title: While loop and mysql_fetch_array - Codeigniter equivalency
body: <p>I'm trying to convert some ancient code to normal PHP standards (I've read about the issues with mysql functions...), I'm using Codeigniter as my framework, this is the original code:</p>
  
  <pre><code>$query_pag_data = "SELECT id,name from messages LIMIT $start, $per_page";
  $result_pag_data = mysql_query($query_pag_data) or die('MySql Error' . mysql_error());
  
  $msg = "";
  
  while ($row = mysql_fetch_array($result_pag_data)) {
  $htmlmsg=htmlentities($row['message']);
      $msg .= "&lt;li&gt;&lt;b&gt;" . $row['msg_id'] . "&lt;/b&gt; " . $htmlmsg . "&lt;/li&gt;";
  }
  
  $msg = "&lt;div class='data'&gt;&lt;ul&gt;" . $msg . "&lt;/ul&gt;&lt;/div&gt;"; // Content for Data
  </code></pre>
  
  <p>This is my attempt:</p>
  
  <pre><code>$this-&gt;load-&gt;model("main_model");
  $result=$this-&gt;main_model-&gt;user_list($start, $per_page);
  
  $msg = "";
  
  foreach ($result-&gt;result() as $row){
       $htmlmsg = htmlentities($row-&gt;name);
       $msg .= "&lt;li&gt;&lt;b&gt;" . $row-&gt;id . "&lt;/b&gt; " . $htmlmsg . "&lt;/li&gt;";
  }
  
  $msg = "&lt;div class='data'&gt;&lt;ul&gt;" . $msg . "&lt;/ul&gt;&lt;/div&gt;"; // Content for Data
  </code></pre>
  
  <p>My model:</p>
  
  <pre><code>function user_list($start, $per_page) {
      $query = $this-&gt;db-&gt;get('users', $start, $per_page); 
      return $query;
  }
  </code></pre>
  
  <p>This is not working correctly though, I believe it has something to do with the while and how mysql_fetch_array works, I've tried a few solutions with a while loop, but don't seem to be getting there.</p>
  
  <p>A bit more info: This is for an ajax pagination feature, my attempt above loads up results, but the foreach loop is now loading previous results in next pages.</p>