Jump to content

I need some advice !!


spraypray12

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.