hostfreak Posted January 22, 2007 Share Posted January 22, 2007 I've got a form that consists of multiple rows of the same input (each unique however). What I am wondering is what would be the best way to store the information in a database. Like make a new row for each one, or separate the information in a single row somehow? Sometimes however, not all fields will be needed. So if I do separate it in the DB, I will need to figure out how to not input the separate(er) mark in the DB. Attached is an example of the form. Also, I know this next question isn't php related, but am hoping someone might be able to answer. As you can see on the form, some of the inputs consists of a price. I want to be able to use ajax/javascript to be able to total them live, but am not sure how. So some advice on that would be appreciated. I found an example of how to do that (http://www.ajaxify.com/run/sum/live/) however it doesn't include the server side coding. Thanks in advanced.[attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/35270-best-way-to-store-in-db/ Share on other sites More sharing options...
craygo Posted January 22, 2007 Share Posted January 22, 2007 if each one is relevent then you would need to store them seperate, But with a key to link them together so they can then be added later. For instance, you can have 20 dollar amounts in the table but have a groupid(or something like that) the same for all of them. that way when you query them you will get what you need.As far as the live addition part I have something which will total that for you. It is Javascript. First you should design your database and tables so you can store your information.Ray Link to comment https://forums.phpfreaks.com/topic/35270-best-way-to-store-in-db/#findComment-166622 Share on other sites More sharing options...
hostfreak Posted January 22, 2007 Author Share Posted January 22, 2007 Alright, So each with there own row, but with a unique group id. As it is now, since each has an individual input field, I have a lot of inputs. For example, for Commercial Labor, I will name the field c_labor. Then when storing it:[code] $c_labor_row1_1 = $_POST['c_labor1_0']; $c_labor_row1_2 = $_POST['c_labor1_1']; $c_labor_row1_3 = $_POST['c_labor1_2']; $c_labor_row1_4 = $_POST['c_labor1_3']; $c_labor_row1_5 = $_POST['c_labor1_4']; $c_labor_row1_6 = $_POST['c_labor1_5']; $c_labor_row2_1 = $_POST['c_labor2_0']; $c_labor_row2_2 = $_POST['c_labor2_1']; $c_labor_row2_3 = $_POST['c_labor2_2']; $c_labor_row2_4 = $_POST['c_labor2_3']; $c_labor_row2_5 = $_POST['c_labor2_4']; $c_labor_row2_6 = $_POST['c_labor2_5']; $c_labor_row3_1 = $_POST['c_labor3_0']; $c_labor_row3_2 = $_POST['c_labor3_1']; $c_labor_row3_3 = $_POST['c_labor3_2']; $c_labor_row3_4 = $_POST['c_labor3_3']; $c_labor_row3_5 = $_POST['c_labor3_4']; $c_labor_row3_6 = $_POST['c_labor3_5']; $c_labor_row4_1 = $_POST['c_labor4_0']; $c_labor_row4_2 = $_POST['c_labor4_1']; $c_labor_row4_3 = $_POST['c_labor4_2']; $c_labor_row4_4 = $_POST['c_labor4_3']; $c_labor_row4_5 = $_POST['c_labor4_4']; $c_labor_row4_6 = $_POST['c_labor4_5']; $c_labor_row5_1 = $_POST['c_labor5_0']; $c_labor_row5_2 = $_POST['c_labor5_1']; $c_labor_row5_3 = $_POST['c_labor5_2']; $c_labor_row5_4 = $_POST['c_labor5_3']; $c_labor_row5_5 = $_POST['c_labor5_4']; $c_labor_row5_6 = $_POST['c_labor5_5']; $c_labor_row6_1 = $_POST['c_labor6_0']; $c_labor_row6_2 = $_POST['c_labor6_1']; $c_labor_row6_3 = $_POST['c_labor6_2']; $c_labor_row6_4 = $_POST['c_labor6_3']; $c_labor_row6_5 = $_POST['c_labor6_4']; $c_labor_row6_6 = $_POST['c_labor6_5']; $c_labor_row7_1 = $_POST['c_labor7_0']; $c_labor_row7_2 = $_POST['c_labor7_1']; $c_labor_row7_3 = $_POST['c_labor7_2']; $c_labor_row7_4 = $_POST['c_labor7_3']; $c_labor_row7_5 = $_POST['c_labor7_4']; $c_labor_row7_6 = $_POST['c_labor7_5']; $c_labor_row8_1 = $_POST['c_labor8_0']; $c_labor_row8_2 = $_POST['c_labor8_1']; $c_labor_row8_3 = $_POST['c_labor8_2']; $c_labor_row8_4 = $_POST['c_labor8_3']; $c_labor_row8_5 = $_POST['c_labor8_4']; $c_labor_row8_6 = $_POST['c_labor8_5'];[/code]Which seems the only way to do it, but too much work. Maybe I should just make a single input for each row? The last column is for change, hence two digits. Link to comment https://forums.phpfreaks.com/topic/35270-best-way-to-store-in-db/#findComment-166647 Share on other sites More sharing options...
hostfreak Posted January 23, 2007 Author Share Posted January 23, 2007 Not sure if my last post is making sense? What I mean is that each column, for example Commercial Labor, I store each input. So instead of doing a new row, as of now, I am separating each input for commercial labor. So the first input would be $c_labor_row1_1 (the last number represents the position in the column). Then separting it in the database like: "-" separates the column ($c_labor_row1_1-$c_labor_row1_2 ... etc) and "|" separates the row ($c_labor_row1_1|$c_labor_row2_1 ... etc). However, now I am thinking instead of making an input for each individual row and column, I should make an input for each row. Then in the database I would have the following (only using Commercial Labor as an example):c_labor_row1c_labor_row2etcIs that the best way to go? Link to comment https://forums.phpfreaks.com/topic/35270-best-way-to-store-in-db/#findComment-166885 Share on other sites More sharing options...
hostfreak Posted January 24, 2007 Author Share Posted January 24, 2007 craygo, I think I have got the database designed how I want it. When you get a chance, please let me know more about the live addition option. Thanks. Link to comment https://forums.phpfreaks.com/topic/35270-best-way-to-store-in-db/#findComment-167753 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.