title: max(id) and limit 10, but use them in different places
body: <p>I have two tables, posts and sections.  I want to get the last 10 posts WHERE section = 1,
  but use the 10 results in different places.  I make a function:</p>
  
  <pre><code>     function sectionposts($section_id){
  mysql_set_charset('utf8');
  $maxpost1 ="SELECT max(id) from posts WHERE section_id = $section_id ORDER BY ID DESC LIMIT 20";
  $maxpost12 =mysql_query($maxpost1);
  while ($maxpost_rows = mysql_fetch_array($maxpost12 ,MYSQL_BOTH)){
  $maxpost2 = $maxpost_rows[0];
  }
  $query = "SELECT * FROM posts WHERE id = $maxpost2";
  $query2 = mysql_query($query);
  return $query2;
  }
  $query2 = sectionposts(6);
  while ($rows = mysql_fetch_array($query2)){
  echo $rows['title'] . "&lt;br/&gt;" . "&lt;br/&gt;";
  echo $rows['id'] . "&lt;br/&gt;" . "&lt;br/&gt;";
  echo $rows['image_section'] . "&lt;br/&gt;";
  echo $rows['subject'] . "&lt;br/&gt;";
  echo $rows['image_post'] . "&lt;br/&gt;";
  }
  </code></pre>
  
  <p>How can it take these ten results but use them in different places, and keep them arranged from one to ten.</p>
  
  <p>this was the old case and i solve it but i found another problem, that, if the client had deleted a post as id = 800 "so there aren't id = 800 in DB" so when i get the max id minus $NUM from it, and this operation must be equal id = 800, so i have a programing mistake here, how can i take care of something like that.</p>
  
  <pre><code>    function getmax_id_with_minus ($minus){
      mysql_set_charset('utf8');
      $maxid ="SELECT max(id) FROM posts";
      $maxid1 =mysql_query($maxid);
          while ($maxid_row = mysql_fetch_array($maxid1)){
                  $maxid_id = $maxid_row['0'];
                  $maxid_minus = $maxid_id - $minus;
                  }
      $selectedpost1 = "SELECT * FROM posts WHERE id = $maxid_minus";
      $query_selectedpost =mysql_query($selectedpost1);
          return ($query_selectedpost);
  
  }
  &lt;?php 
  $ss = getmax_id_with_minus (8);
  while ($rows = mysql_fetch_assoc($ss)){
  $main_post_1 = $rows;
  ?&gt;
  </code></pre>
  
  <p>anyway "really" thanks again :) !</p>