[Database class] Generating order numbers

Paul S. Wang pwang at cs.kent.edu
Wed Mar 7 12:44:59 EST 2012


Dear DB class,

There was a question of generating order numbers.  Of course
writing a function for that in your particular application context
would be the answer.  Here is an example:
<?php   /////    genOrd.php    /////
      function genOrd()
      {  $prefix="ord_";
         if ( function_exists("date_default_timezone_set") )
	    date_default_timezone_set('US/Eastern');
         $dt=date("Md");
	 $r=rand(10000000, 99999999);
	 return "$prefix".$dt."_".$r;
      }

      echo genOrd();
?>

Also, when a new order is entered into the orders table,
a duplicate order number would cause an error.  So that needs to
be checked as always with any query.

Paul

-- 
==============================================================================
 Paul S. Wang (王士弘)                      Email: pwang at cs.kent.edu            
 Dept. of Computer Science, Kent State U.   Tel: (330) 672-9051
 Kent, Ohio, USA 44242-0001                 http://www.cs.kent.edu/~pwang/ 
==============================================================================


More information about the Dbclass mailing list