[thelist] PHP/MySQL dates, times and autoincrements

John Corry webshot at members.evolt.org
Fri Apr 26 17:27:11 CDT 2002


I'm about 75% done with the most complex thing I've ever built and I need a little help to get the rest of the way there.

1) I'm working A LOT with dates and times in PHP/MySQL. PHP seems to rely on timestamps, but the MySQL datetime type is a string. Generally, it seems like I might be best off working with timestamps in my scripts, and converting to the MySQL datetime format when I store values in the db. Can anyone confirm that I'm thinking straight or clue me in to anything I might be missing?

2) In my hand rolled ordering process, a user goes through a series of forms, all of the values are finally displayed on a 'confirm your order' page (and all the values they entered are on the page as hidden form fields) with a submit button to 'confirm'. OK...now I have to write the script that happens when you confirm. This script will
1) create a customer in the customer table
2) create a recipient (of flowers) in the recipient table
3) create an order in the orders table

Ok...I have to run the queries so that I insert the new customer and new resipient first, then get their ID numbers to store in the orders table. So, MySQL has a LAST_INSERT_ID() function. Does MySQL support using a SELECT statement for a value in an insert statment? (as in, 'insert into orders (ordCust) values (select custID from customers where custID = LAST_INSERT_ID())')? If not...how do I get the users id? I am using sessions...I guess I could store the session id in a column and match that way, but still I have to run the 2 insert queries (insert the customer and the recipient, then select the customer and recipient id's, then insert the order. That's 4 queries...is that OK? Is there a more streamlined way to do this?

I'm in way over my head here and it is not fun :(

<tip type="rhetorical">
Bored with static web page design? Thinking of trying to build a dynamic, database driven site with processes and transactions and advanced user interaction? I reccomend taking your time, going slow, progressing in baby steps. Having a major deadline looming, and no idea of what you're doing...it sucks.
</tip>

John




More information about the thelist mailing list