Re: How to write a query to insert a blank row in a MySQL table?
|
Dhamayanthi Nadesan |
|
5/11/2008 10:57:23 PM |
Problem solved !!!
Code: //connect to db mysql_query("INSERT INTO tbl_name VALUES ()"); $inserted_id = mysql_insert_id(); print "&number=".$inserted_id;
Post Comments |
|
Sounds like you need to employ...
|
Rajeev Saurav |
|
5/11/2008 11:07:38 PM |
Hmm, sounds like you need to employ some lazy db queries, instead of running a query twice (potentially). Interesting though: in what sort of application/reasoning are you doing this? I can see what you're getting back (the id) but where is it being used that stops you from entering the information at the same time?
Post Comments |
|
That's just plain silly
why not just eliminate this "insert blank row" nonsense and do the insert using the collected data later
Post Comments |
|
Re: How to write a query to insert a blank row in a MySQL table?
|
Taslima Hassan |
|
5/11/2008 11:08:58 PM |
I could understand it...
Perhaps there is foreign key information that needs to be stored now and you don't have the information to fill in the master record..?
Can 't think of a real life situation, but I can appreciate the sentiment. Post Comments |
|
Re: How to write a query to insert a blank row in a MySQL table?
|
Sabir. H. Mohammad |
|
5/11/2008 11:13:22 PM |
To appreciate the horror of this requirement you need to read this in conjunction with http://www.dbforums.com/showthread.php?t=1627763the autonumber value is to be used for an ordernumber quoted to the customer. its the age old problem of coercing the surrogate key into having meaning outside the system. it'll end in tears..... Post Comments |
|
Quote of the week!!! Post Comments |
|
Re: I love this "order number" stuff
|
Rajeev Saurav |
|
5/11/2008 11:15:59 PM |
I love this "order number" stuff. I saw another post elsewhere on a different forum, looking suspiciously the same , asking how to perform exactly this. At which point we noted that an order DOESN'T become an order until the final button "checkout" or "processing payment" is pressed, at which point everything in your shopping basket then becomes an order, and gets assigned a number, and entered into all it's relevant tables. Giving someone an order number before they've ordered seems a bit like nonsense...
However, if you're dealing with "quotes" that's slightly different, but I think should probably maintain the same path. What's the point in giving someone a quote number until they're formalised their quote. (i.e. logged out, saved as "quote"). Again, it doesn't get inserted into the table and given a number until it's completed.
I hate to think how many blank records get created using this methodology, but it makes me shudder to think I have to use ALLOW NULL on all my columns
Post Comments |
|
Not a good idea .. Lots of "blank" records .. lots of unintended null fields yes .. but most importantly .,. any multi user system now can get spurious writes to the same ID.
A better solution is to create a separate capture table that you store a username, timestamp or session # in and then allow for the capture and fiddling. When you programatically decide that you have the correct data .. write it to that master table that has all the pack drill , checks and balances.. Housekeep the capture table regularly with deletes..
Good luc k Post Comments |
|