I'm not exactly sure where to post this - in html, php, or mysql area but since this is mostly php oriented, I figure I'll post it here for starters til I get yelled at ><

Background info:
This is not for the general public, nor attached to any website, and tho it is online it will have only one user at any given time - with login/password so I'm not worried about how this is really implemented.

What I'm trying to do:
I'm trying to write a receipt generator. It works beautifully with only one item, however, my problems start with multiple items.

Page 1:
User is asked how many different items are being purchased.

Page 2:
A form is printed, with fields for item, quantity, description, and cost, so 4 fields total for every unique item.

Page 3:
Checks for already existing customer -
if not
Updates mysql database with the 4 fields plus customer id, order id, and a datetime stamp - and in a seperate table adds the customer's name, phone number, and unique id for that customer
else
Updates mysql database with the 4 fields plus customer id, order id, and a datetime stamp and in the other table nothing is changed

Page 4:
Generates the total cost and the customer's name, phone number, and the information submitted from page 2, and prints out the receipt in a tasteful layout

The goal is to make this receipt generator as quick as possible, because time is of the essence. I could make a seperate form for every item on a seperate page or whatever for however many uniqe items are entered, and carry all the information from one page to another manually - but since the amount of items is undetermined it would take years to get up to 100,000 items and the amount of pages would be impractical, not to mention each page would get substantially larger since I have to keep adding the previous carried over variables.

What I would like to do:
After the user enters however many unique items are being sold the next page will display the 4 fields for each item (so if 3 unique items are being sold there will be 12 fields displayed - 3 sets of 4 fields) - with each set of 4 fields having some sort of unique identifier which carries onto the 3rd page and only having a single submit button to go to the next page that will process the information.

I know the best way to do this (at least logically to me) is to implement 4 arrays somehow, and then use 4 for loops to spit out the information into the database and into the receipt itself, or use 1 multi-dimensional array, but I haven't really played around with multi-dimensional arrays much.

I thought about doing it thru session handling, but I don't know where exactly I should do this, or if a user can even input information directly into a $_SESSION variable. I seriously doubt it can be done - at least legally - I also don't think it's possible to take a form submission of multiple fields - parse the fields and put the corresponding fields into the correct session array - like item0 goes into $_SESSION[0] and so on...

So I'm kinda stumped here. If anyone has any ideas behind the logic of what I should do I am anxious to hear about it. I would include code but I dont think that this question warrants any, tho if you would like to see what I have I can post it.

Thank you for any help or suggestions.

Recommended Answers

All 4 Replies

There are ajax scripts that dynamically create form rows for 'another item' and populate the array as the form is created
then the array is posted and price fields populated from the database
something like
http://www.agoracart.com/ freeware
http://www.myezshop.com/ payware
and there are tutorials on creating the script in php to do your own
http://www.developer.com/services/article.php/3656001
http://nettuts.com/javascript-ajax/build-an-ajax-powered-shopping-cart/
it may be quicker and more accurate to integrate the tutorial into your software, than to completely code from scratch

cool, thank you I will definitely check that out

I dont have much experience with ajax, but I am going to school for software engineering so I'm teaching myself a lot of languages at the same time I'm learning others - ajax isn't exactly at the top of the list but at the same point in time - I am making projects for myself and if it includes the need for another language - I'm all for it :)

ajax isnt that hard
its pretty much javascript and php at the same time
and very [edit='left out the expletive deleted word']easy[/edit] to implement


ps I know this board does not support smartass psuedo tags but I am having a little fun

What version of php are using? Have you not thought about using OO and classes to hold each item. Then you could just populate one array with the item object and use properties to return the various values?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.