Jump to content
Dan Cole

Unique orders status id.

Recommended Posts

I'm looking to update an old payment module Interac Email Money Transfer and it adds an orders status id to the database to set up an order status of "Waiting for Payment".  Unfortunately it just adds the orders_status_id of 4 in a table update as follows:

tep_db_query("insert into orders_status (orders_status_id, language_id, orders_status_name ) values ('4', '1', 'Waiting for payment')");

In my case I already have an orders_status_id of 4 in my database so it fails.  Obviously I can easily fudge the id in my case but if I'm going to upload the contribution back to the community it'll cause problems for others so I'm wondering if there is a simple way to just have it add a unique id to the database or if I need to query the database for the last added id and go from there?  That too is not a problem but this has me wondering if that is the best/simplest approach.  Suggestions anyone?

Dan

Share this post


Link to post
Share on other sites
tep_db_query("INSERT INTO orders_status (orders_status_id, language_id, orders_status_name ) SELECT MAX(orders_status_id) + 1, '1', 'Waiting for payment' FROM orders_status");

I believe that works.  Test of course.  First by running just the select in phpMyAdmin or similar and then try to write with it if the results are what you expect. 


Always back up before making changes.

Share this post


Link to post
Share on other sites
1 hour ago, ecartz said:

tep_db_query("INSERT INTO orders_status (orders_status_id, language_id, orders_status_name ) SELECT MAX(orders_status_id) + 1, '1', 'Waiting for payment' FROM orders_status");

I believe that works.  Test of course.  First by running just the select in phpMyAdmin or similar and then try to write with it if the results are what you expect. 

That's awesome and works perfectly.  Thanks Matt.  I appreciate it.

Dan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×