Generate serialize number

I use a control to get 2 input from customer. Let name it startno and qtu.

If customer enter 20 as startno and 50 as qty, then system will insert 21, 22, 23, … 68, 69, 70. to the table.

If customer enter 101 as startno and 200 as qty, then system will insert 101, 102, 103, … 298, 299, 300 to the table.

My question is, how to write a code in onValidate events to make above entry work?

Re: Generate serialize number

Here is some code I used to generate card numbers for an app… perhaps it may help.

Regards,
Scott



$idBatch = date('YmdHis');
$nowStr = date('Y-m-d');
$DefaultLevel = 0;  // not programmed
$DefaultActivityType = 1; // in stock

$Building = {input_building};
$StartCard = {input_startcard};
$CardCount = {input_count};
$Comment = {input_comment};

$CurrentUserID = $_SESSION['g_idUser'];

if (is_numeric($StartCard)) { 
 if ($StartCard > 0) {
  $_duplicates_found = 0; 
  // check database for no duplicates, cancel batch if any present
  for ($newCardno = $StartCard; $newCardno < ($StartCard+$CardCount); $newCardno += 1) {
   $padCardno = str_pad($newCardno, 5, '0', STR_PAD_LEFT);
  
   $sql = 'SELECT COUNT(*) FROM AccessCards WHERE cardno = "'.$padCardno.'"';
   sc_lookup(db_cards,$sql);

   if ({db_cards[0][0]} > 0) {
    $_duplicates_found++;
   }
  } 
 
  if ($_duplicates_found > 0) {
   sc_error_message('There were '.$_duplicates_found.' duplicate cards found, please verify batch entry');  
  } else {
  // add to database, need update VALUES code to insert once instead of 1 by 1 as SC5 does not allow ';' to script multiple sql statements.
  for ($newCardno = $StartCard; $newCardno < ($StartCard+$CardCount); $newCardno += 1) {
   $padCardno = str_pad($newCardno, 5, '0', STR_PAD_LEFT);

   $sql = 'INSERT INTO `AccessCards` ';
   $sql .=  '(idBatch,cardno,idLevel,dateOrdered,dateReceived,dateUpdated,idActivityType,idBuilding,idUser)';
   $sql .= 'VALUES';
   $sql .= '("'.$idBatch.'","'.$padCardno.'",'.$DefaultLevel.',"'.$nowStr.'","'.$nowStr.'","'.$nowStr.'",'.$DefaultActivityType.','.$Building.','.$CurrentUserID.')';
   
   sc_exec_sql($sql); // or die("Invalid Query: ".$sql);
  }
  
  ?>
  
  <script language="JavaScript">
   alert("Cards have been generated, click OK to continue");
  </script>   
  
  <?php
   
  sc_redir(grid_accesscards.php);
  } 
 }
}



Re: Generate serialize number

you really great scott.

regards,
ghulma