[PHP] Re: Auto Incrementing in PHP

2003-01-19 Thread Don Mc Nair
Thanks Guys

I just needed a pointer. I decided to use the database and created two
tables, one for invoice number and one for order number then defined a
function to read the current number and the increment it.

// GET AUTO NUMBER and creates the next one
// uses the parameter tablename as $table

function get_auto_number($table)
 {
  if(!$table)
   {
echo The Function get_auto_number requires the peramater 'tablename' to
allow it to know which auto number you want.br;
exit;
   }
  $query = 'select number from '.$table;
  $result = mysql_query($query);
  if (!$result)
   {
echo Sorry there is a problem getting the auto_number from the
table .$table.br;
exit;
   }
  $current_number = mysql_fetch_row($result);
  global $auto_number;
  $auto_number = $current_number[0];
  $query = update .$table. SET number = '.($auto_number +1).';
  $result = mysql_query($query);
 }

Simple when someone tells you what to do :o)

Thanks and regards.





Don Mc Nair [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Hi

 Is there a way for a php page to automatically increment a number and
store
 it every time the page is loaded.

 I want to generate an invoice number that goes up 1 everytime the HTML
form
 is sent to it.

 Thanks


 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.435 / Virus Database: 244 - Release Date: 01/01/2003




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.435 / Virus Database: 244 - Release Date: 02/01/2003



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: Auto Incrementing in PHP

2003-01-19 Thread Don Read

On 19-Jan-2003 Don Mc Nair wrote:
 Thanks Guys
 
 I just needed a pointer. I decided to use the database and created two
 tables, one for invoice number and one for order number then defined a
 function to read the current number and the increment it.
 

That'll work, but it's not atomic. At high traffic loads you can get
duplicates.

You might want to consider a table with a auto_increment field. Do a dummy
insert, the get the value with :

mysql_query('SELECT last_insert_id() as id');


Regards,
-- 
Don Read   [EMAIL PROTECTED]
-- Beer is proof that God loves us and wants us to be happy.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Auto Incrementing in PHP

2003-01-18 Thread Bobby Patel
One quick note, if you DO NOT have access to a database, you could store
that incremented number to a file. And open and retrieve, and increment
every time you need. If you need to take this approach checkout php.net and
search for fopen.



Don Mc Nair [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Hi

 Is there a way for a php page to automatically increment a number and
store
 it every time the page is loaded.

 I want to generate an invoice number that goes up 1 everytime the HTML
form
 is sent to it.

 Thanks


 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.435 / Virus Database: 244 - Release Date: 01/01/2003





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php