Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/248117-help-with-invoice-rowslines/
Share on other sites

.... 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

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>';
}

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

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.

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.

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.

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.