Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

working with sequences

Status
Not open for further replies.

vz

MIS
Jul 31, 2001
131
US
I am trying to create a form that when the user clicks submit the order_id field will automatically populate with the next number. I have created a sequence in postgresql the db i am using, but I can't figure out how to get the form to automatically use the sequence and insert that number in that field here is part of my code:
<FORM name=&quot;addordersplacedform&quot; action=&quot;postordersplaceddata.cfm&quot; method=&quot;Post&quot;><FONT face=&quot;arial&quot; size=&quot;3&quot;>
<INPUT type=&quot;hidden&quot; name=&quot;order_id&quot; size=&quot;8&quot; maxlength=&quot;8&quot; value=&quot;#nextval(seq_ordersplaced)#&quot;><BR><FONT face=&quot;arial&quot; size=&quot;3&quot;>Account Number:</FONT>
<INPUT type=&quot;text&quot; name=&quot;accountnumber&quot; size=&quot;8&quot; maxlength=&quot;8&quot;><BR><FONT face=&quot;arial&quot; size=&quot;3&quot;>Account Name:</FONT>
<INPUT type=&quot;text&quot; name=&quot;accountname&quot; size=&quot;50&quot; maxlength=&quot;50&quot;><BR><FONT face=&quot;arial&quot; size=&quot;3&quot;>Order Date:</FONT>
<INPUT type=&quot;Text&quot; name=&quot;orderdate&quot; size=&quot;10&quot; maxlength=&quot;50&quot;><BR><FONT face=&quot;arial&quot; size=&quot;3&quot;>Tubes:</FONT>
<INPUT type=&quot;Text&quot; name=&quot;tubes&quot; size=&quot;10&quot; maxlength=&quot;50&quot;><BR><FONT face=&quot;arial&quot; size=&quot;3&quot;>Needles:</FONT>
<INPUT type=&quot;Text&quot; name=&quot;needles&quot; size=&quot;10&quot; maxlength=&quot;50&quot;><BR><FONT face=&quot;arial&quot; size=&quot;3&quot;>Butterfly:</
 
Hey VZ,

If you are manually creating your order ids, I would use the max() function to find the current largest order number and then set the next order to that value plus 1. Here's an example for the postordersplaceddata.cfm page.

<!--- Insert the order --->
<cfinsert .....>

<cfquery name=&quot;order&quot; datasource=&quot;myDs&quot;>
select max(order_id) as num from myOrdersTable
</cfquery>

......

<cfoutput>
<input type=&quot;hidden&quot; name=&quot;order_id&quot; value=&quot;#evaluate(#order.num#+1)#&quot;>
</cfoutput>

Hope this helps,
GJ
 
no i am trying to create my auto numnbers using a sequence, not manually. I have a default set up but it doesn't seem to be working.
 
hi vz

You posted earlier regarding another postgres issue.

By default, are you saying that you have a column that should auto increment... and that it is not? Try the following:

DROP TABLE myT;
DROP SEQUENCE myT_primaryid_seq;

CREATE TABLE myT (
primaryid SERIAL PRIMARY KEY,
name VARCHAR(32) );

insert into myT (name) values ('testName');
insert into myT (name) values ('testName2');

The record with testName2 should have some value for the auto increment column.. are you saying that it has no value? What isn't working, please be specific.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top