spraypray12 Posted April 25, 2007 Share Posted April 25, 2007 I have a form where users can submit orders for review, and the data is stored in a mysql table. I've added a function in javascript to add rows to the form as needed, so they can submit all there data at one time. The problem i have now is, i have to add columns to the mysql table, for each of the new rows added to the form. Should i limit the amount of rows that can be added, or make a script that adds another colum to mysql after so many rows added. I hope you understand what i'm trying to say. Any suggestion would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
marmite Posted April 25, 2007 Share Posted April 25, 2007 Hi, I'm quite new to this, but from my knowledge of table structures, you don't want to be adding columns to a table; they are designed to have rows added. You can usually restructure a table to work add rows instead, with a bit of head scratching. Maybe post your table structure up here and we can have a look. Quote Link to comment Share on other sites More sharing options...
Anzeo Posted April 25, 2007 Share Posted April 25, 2007 What do you need to add columns for? As marmite noticed, columns hold your attributes while a row holds a record. Give us the situation where you want to add a column. Quote Link to comment Share on other sites More sharing options...
spraypray12 Posted April 25, 2007 Author Share Posted April 25, 2007 I have a table with about 30 columns, each for a different text input, and the rows are ordered by id, to seperate out each submission sent in. I would like to add row(to the form) which would in turn, mean more text inputs, hence more colums. I know that i can do the alter table (table) add column (column) if need be, but i don't want to have a giant table Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted April 25, 2007 Share Posted April 25, 2007 How about a link to an example page of what you're trying to accomplish? From your description so far it sounds like you're going about this all wrong. Quote Link to comment Share on other sites More sharing options...
spraypray12 Posted April 25, 2007 Author Share Posted April 25, 2007 http://www.redmond.k12.or.us/rhs/php/orderform/addrow.php < -- adds the rows(test) http://www.redmond.k12.or.us/rhs/php/orderform/form.php<--working (doesn't add rows) Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted April 25, 2007 Share Posted April 25, 2007 So why do you need to add extra columns to your DB table? Your table should have at least 5 columns: quantity catalog desc price ext_price And probably an internal column: id Why does your table already have 30 columns? There's a good chance you're not normalizing your database. Post your table layout like someone suggested earlier and you might get some real help. Quote Link to comment Share on other sites More sharing options...
spraypray12 Posted April 25, 2007 Author Share Posted April 25, 2007 don't have to time to post now, but have that many, because each new row of desc, catalog, ect..., needs to have it's own place here are current coulmns Date,Requestor,Student_Body,District,Grant_or_Other,Vendor_Name,Address,Address_Line_2,Phone,Fax,q1,q2,q3,q4,q5,q6,c1,c2,c3,c4,c5,c6,d1,d2,d3,d4,d5,d6,p1,p2,p3,p4,p5,p6,e1,e2,e3,e4,e5,e6,Shipping_Estimate,Total Quote Link to comment Share on other sites More sharing options...
Anzeo Posted April 25, 2007 Share Posted April 25, 2007 When you have time, explain us why you have so much columns. As roopurt said, in order for your form to work, you'd only need 5 columns. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted April 25, 2007 Share Posted April 25, 2007 The underlying problem is you're trying to battle a bad database design through programming. You should break this apart into at least two tables, potentially three (if you plan to have repeat customers). order_desc id date requestor student_body district grant_or_other vendor_name addr1 addr2 phone fax order_items id order_id quantity catalog desc price ext_price You place the general order information (your top fields) into the order_desc table. Then you insert each item in the order into it's own row in the order_items table. For each item row inserted, you also insert the order_id the item was attached to. Note that I've intentionally left out the shipping estimate because this is something you should calculate on the fly and display to the customer but you may not really need to store it in the DB. I've also left off the total column because you can calculate an order total based off the items table, although you may want to add a column to the order_desc table indicating how much the customer was charged. You may find this Wiki article helpful: http://en.wikipedia.org/wiki/Database_normalization Quote Link to comment Share on other sites More sharing options...
sw0o0sh Posted April 25, 2007 Share Posted April 25, 2007 Uhh, like everyone here is saying, you dont need a new column (truncating the table) for everybodys address. You notice the "browse" feature uptop? (If your looking through phpmyadmin). Consider this the look. and yeah, an auto_increment id int(11) is being used in this example ID Requestor Student_body District _ ... etc 1 Request_1 Student_body1 district_1 2 request_2 student_body2 district_2.. and so forth in that array. What you are you doing is totally redudant. Quote Link to comment Share on other sites More sharing options...
spraypray12 Posted April 26, 2007 Author Share Posted April 26, 2007 ok, i see now. How would i use the order id? How would i keep it the same during for each row, during that order. I'm having trouble wrapping my head around it right now. Also, this isn't for buying or anything like that. It's just for people to send in stuff they want to get ordered. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.