jimbob_2011 Posted September 29, 2011 Share Posted September 29, 2011 Hi all, Hopefully this will be a very easy question for one of you! Basically, I've created a little invoice script, and I need some help with the invoice data (i.e the item info, qty and the price). My question is how do i deal with the data from multiple rows containing 3 text fields each (item, qty and price). I've been playing with a foreach loop, which I can make echo info in the item field for each row. How do I incorporate the other fields (the qty and price)? Can I build an array to hold it all? Thanks for any help! Jim Quote Link to comment https://forums.phpfreaks.com/topic/248117-help-with-invoice-rowslines/ Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 Showing us some of your code might help. Quote Link to comment https://forums.phpfreaks.com/topic/248117-help-with-invoice-rowslines/#findComment-1274076 Share on other sites More sharing options...
jimbob_2011 Posted September 29, 2011 Author Share Posted September 29, 2011 .... sorry! The HTML ... <div id='d1' class="invoice_row"> <div class="invoice_row_item"><input name="row[1]" type="textbox" id="row1" class="invoice_input"></div> <div class="invoice_row_qty"><input name="qty[1]" type="textbox" id="qty1" class="invoice_input" value="1"></div> <div class="invoice_row_price"><input name="price[1]" type="textbox" id="price1" class="invoice_input"></div> </div> That then just repeats for as many invoice lines as I fancy. On the PHP side of things all I have I just the loop I've tried, which is ... foreach($_POST['row'] as $id=>$data){ echo $data .'-'. $id .'<br>'; } Thanks, Jim Quote Link to comment https://forums.phpfreaks.com/topic/248117-help-with-invoice-rowslines/#findComment-1274083 Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 In your foreach loop you are assigning $id with the key. Which means you can get the other information foreach($_POST['row'] as $id=>$data){ $price = $_POST['price'][$id]; $qty = $_POST['qty'][$id]; echo $data .'-'. $id .'<br>'; } Quote Link to comment https://forums.phpfreaks.com/topic/248117-help-with-invoice-rowslines/#findComment-1274096 Share on other sites More sharing options...
jimbob_2011 Posted September 29, 2011 Author Share Posted September 29, 2011 Thats great! My plan is to serialize the data to store it in the database, does that sound ok? How would I serialize that now, before I used, which seemed to work ... $items = serialize($_POST['row']); What would the code be now? Sorry for being a pain! Jim Quote Link to comment https://forums.phpfreaks.com/topic/248117-help-with-invoice-rowslines/#findComment-1274101 Share on other sites More sharing options...
mikesta707 Posted September 29, 2011 Share Posted September 29, 2011 well serialize will work on non-simple php variables (like arrays, which $_POST['row'] now is) so serialize($_POST['row']) should still "work." You just have to make sure you treat the data returned from the database as an array once you unserialize it. Quote Link to comment https://forums.phpfreaks.com/topic/248117-help-with-invoice-rowslines/#findComment-1274118 Share on other sites More sharing options...
AbraCadaver Posted September 29, 2011 Share Posted September 29, 2011 Thats great! My plan is to serialize the data to store it in the database, does that sound ok? How would I serialize that now, before I used, which seemed to work ... $items = serialize($_POST['row']); What would the code be now? Sorry for being a pain! Jim Why serialize() it? Just store the id, price, qty in those columns in rows. Quote Link to comment https://forums.phpfreaks.com/topic/248117-help-with-invoice-rowslines/#findComment-1274123 Share on other sites More sharing options...
jimbob_2011 Posted September 29, 2011 Author Share Posted September 29, 2011 Thats great! My plan is to serialize the data to store it in the database, does that sound ok? How would I serialize that now, before I used, which seemed to work ... $items = serialize($_POST['row']); What would the code be now? Sorry for being a pain! Jim Why serialize() it? Just store the id, price, qty in those columns in rows. I wanted to store the data in 1 place, rather then having a load of columns. I'm allowing upto 30 rows on the invoice, so would that mean I'd need 90 columns? Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/248117-help-with-invoice-rowslines/#findComment-1274148 Share on other sites More sharing options...
AbraCadaver Posted September 29, 2011 Share Posted September 29, 2011 No, 3 columns: id, price, qty: and 30 rows. Quote Link to comment https://forums.phpfreaks.com/topic/248117-help-with-invoice-rowslines/#findComment-1274157 Share on other sites More sharing options...
jimbob_2011 Posted September 29, 2011 Author Share Posted September 29, 2011 No, 3 columns: id, price, qty: and 30 rows. Ok then, I'll create a new table, then run the foreach loop to add each row into that table. Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/248117-help-with-invoice-rowslines/#findComment-1274162 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.