title: About determining the level id value (user defined field["level_id"]) of a record in mysql
body: <p>Can somebody help me with this code. I can't figure out how to exactly put the value of 1 starting at the 5th record at the level_id field. It always remains as 0 then the 6th record is started as 1.</p>
  
  <pre><code>    CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_EncodePerson`(
      in p_memberId varchar(45),
      in p_encodeId varchar(100))
  
      BEGIN
  
      DECLARE Lev0 varchar(5);
      DECLARE Lev1 varchar(5);
  
      SET Lev0 = "0";
      SET Lev1 = "1";
  
      SELECT @total := count(*) from gph_acquiredpeople 
      where member_Id = p_memberId;
  
  IF @total &lt;= 4 THEN 
      INSERT INTO gph_acquiredpeople
      (member_id,encoded_mem_Id,date_encoded,level_id)
      VALUES (p_memberId,p_encodeId,NOW(),Lev0);
      UPDATE gph_memberstatus SET available ="0", taken = "1"
      WHERE Id_number = p_encodeId;
  
  ELSEIF @total = 5 OR @total &gt;= 5 AND @total &lt; 25 THEN
      INSERT INTO gph_acquiredpeople
      (member_id,encoded_mem_Id,date_encoded,level_id)
      VALUES (p_memberId,p_encodeId,NOW(),Lev1);
      UPDATE gph_memberstatus SET available ="0", taken = "1"
      WHERE Id_number = p_encodeId;        
  ELSE
      BEGIN        
      END;
  END IF;
  END
  </code></pre>