title: How to show only last 5 rows from DataBase using foreach
body: <p>Hi i have database table called Log,
  I want to show only the last 5 rows from this dabatase .
  Here my code :</p>
  
  <p>php :</p>
  
  <pre><code>function get_log_data(){
      $query = "SELECT * FROM log";
      mysql_query("SET NAMES 'utf8'");
      $result = mysql_query($query, $this-&gt;connection);
  
      if(!$result) //ERROR IN YOUR SQL QUERY
      return false;
  
      if(mysql_num_rows($result)==0) //NO ROWS IN TABLE pages
      return false;
  
      while($row = mysql_fetch_array($result, MYSQL_ASSOC)) // CHANGE THE RESULT TO 2 DIMMENSIONAL ARRAY
      {
          $returned_array[] = $row;
      }
      return $returned_array;
  }
  </code></pre>
  
  <p>on the html :</p>
  
  <pre><code>$log_data = $func-&gt;get_log_data();
  
  &lt;table cellspacing="0" cellpadding="0" style="width: 100%"&gt;
      &lt;?php
          foreach($log_data as $key=&gt;$value)
          {
              echo '&lt;tr &gt;';
              echo '&lt;td class="count" style="width:20px;text-align:center;"&gt;.&lt;/td&gt;&lt;td&gt;'. $value['action'].' : '.$value['user'].' .&lt;/td&gt;';
              echo '&lt;/tr &gt;';
          }
      ?&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>i want to foreach only 5 last and no more
  Thanks.</p>