afam4eva Posted November 23, 2009 Share Posted November 23, 2009 Pls i need help with generating an invoice no for my website. Currently i made use of the sql function "create table order(invoice_no serial auto_increment)" to generate unique invoice numbers. But my problem is that the invoice number does not display on the page except i reload the browser. Let me make it more lucid to you. For example you cannot "insert into orders(invoice) values('')" and also "select * from orders" on the same page. So what options do i have left. Link to comment https://forums.phpfreaks.com/topic/182615-help-with-generating-invoice-number-with-php/ Share on other sites More sharing options...
onlyican Posted November 23, 2009 Share Posted November 23, 2009 Why can you not run an insert then select from the table straight after? Link to comment https://forums.phpfreaks.com/topic/182615-help-with-generating-invoice-number-with-php/#findComment-963828 Share on other sites More sharing options...
onlyican Posted November 23, 2009 Share Posted November 23, 2009 Also, not sure if it works in MySQL. I believe it does Just after your INSERT Query, run a new query SELECT @@IDENTITY AS PK Link to comment https://forums.phpfreaks.com/topic/182615-help-with-generating-invoice-number-with-php/#findComment-963830 Share on other sites More sharing options...
afam4eva Posted November 23, 2009 Author Share Posted November 23, 2009 Also, not sure if it works in MySQL. I believe it does Just after your INSERT Query, run a new query SELECT @@IDENTITY AS PK Tha exactly what i did but it doesn't work. I 'll have to refresh the page for the invoice number to show. Link to comment https://forums.phpfreaks.com/topic/182615-help-with-generating-invoice-number-with-php/#findComment-963833 Share on other sites More sharing options...
onlyican Posted November 23, 2009 Share Posted November 23, 2009 Why? Run your query at the top of the page, assign the PK to a variable, then you can echo the PK any point after. Link to comment https://forums.phpfreaks.com/topic/182615-help-with-generating-invoice-number-with-php/#findComment-963834 Share on other sites More sharing options...
afam4eva Posted November 23, 2009 Author Share Posted November 23, 2009 Why? Run your query at the top of the page, assign the PK to a variable, then you can echo the PK any point after. Provided it's on the same page it won't work. Because it'll have to insert before you can select. Link to comment https://forums.phpfreaks.com/topic/182615-help-with-generating-invoice-number-with-php/#findComment-963841 Share on other sites More sharing options...
onlyican Posted November 23, 2009 Share Posted November 23, 2009 yes, but you can run more than 1 query on a page. and SELECT @@IDENTITY will ONLY work if run STRAIGHT after your INSERT Link to comment https://forums.phpfreaks.com/topic/182615-help-with-generating-invoice-number-with-php/#findComment-963843 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.