Programming Theory
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesProgramming Theory

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old November 16th, 2003, 05:36 PM
postalcow postalcow is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Ford CIty, PA USA
Posts: 1,267 postalcow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to postalcow
Best way to save data question

OK, I have a question now. I need some theory on the best way to do this.

I am creating an invoicing application.

I have a problem with the amount of products to be added. I could easily create 10 fields and have 10 items in the database for products ordered but that limits me to 10.

So at first I did it this way. I had a scrolling text box. Each time an item was added; it refreshed the page and added it to the text box. Then I did a preg_match_all() for the dollar amounts and added them for the total. Then I only had to save the value of the text box. That was easy, but this greatly limits editing the invoice.

What would be the best way to add unlimited line items with, Item Number, Description, Qty, Total, and Taxable? And save it to the database so it is editable?

Code, I can write I am looking for the best way to tackle this.

Thx,
~Cow

Reply With Quote
  #2  
Old November 16th, 2003, 06:03 PM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 4
Send a message via Yahoo to nazly
RE: Best way to save data question

As if I understood it I will be doing something else like this. I like using arrays and strings a lot. Since PHP has a lof of functions related to strings and arrays it makes life easier.

I will be storing all the product information as a single string on a single field.
Something else like this.. Say for two products the string would look look this.

itno1,desc1,qty1,total1,taxable1|itno2,desc2,qty2, total2,taxable2

There are two delimeters here. '|' for seperating the products and ',' for seperating fields of the product. To add more products you merge more values seperated with the respective delimeter.

Simply you can use your scrolling text box containing this string. Or say for easy editing if you want to use the form with text fields representing each an every field of the product you can fill the data by using the friendly explode() function for breaking the string into records and then to fields. You can name the text box names as array elements which then enables you to use implode() easily to create the string of data.

I hope I'm clear. The drawback of using this method is that when quering the database with SQL statements. Like I want the sum of all products for that particular order.

For these kinda thing I use seperate fields and store the total when I'm adding the product itself using the code.

The SET field type I think is used to do this kinda thing. But I'm not used to it that much. If there are other ways please post. Probably I can use that method as well.

Reply With Quote
  #3  
Old November 16th, 2003, 06:07 PM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 4
Send a message via Yahoo to nazly
RE: Best way to save data question

I have edited my previous post.. I made a small mistake by using the functions at the wrong place.. Read it again if you have previously read it before I edited it. Sorry for the mess.

Reply With Quote
  #4  
Old November 16th, 2003, 06:42 PM
postalcow postalcow is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Ford CIty, PA USA
Posts: 1,267 postalcow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to postalcow
RE: Best way to save data question

That is not a bad idea. Like you said explode it into an array then I could even loop and put each into a seperate field of its own. Then passing the total line items to the refresh page after editing...

Hmm, So far thats better than anything I had.

Reply With Quote
  #5  
Old November 17th, 2003, 12:17 AM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 4
Send a message via Yahoo to nazly
RE: Best way to save data question

Yep.. It makes things easier when you have them in an array.
I use TEXT as field type for storing this string in the database. Coz this is the best way I could come up with as you can add as much products as you want for a particular order(record).
If you or anyone else come across a method of doing this please post it in. It might be a great help for me too.

Reply With Quote
  #6  
Old November 17th, 2003, 03:29 PM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Best way to save data question

the right way: two tables

Code:
invoices
--------------------
id          int (autoincrement)
date        int
etc...

invoice_products
--------------------
invoice_id  int
product_id  int
quantity    int
etc...


for every product in the invoice, you INSERT another row into the invoice_products table, set the invoice_id, product_id, quantity, etc..

when you need to list them, you just SELECT * FROM invoice_products WHERE invoice_id='$id'

etc. also, you can add/remove/view/edit product in invoices, and by joining this with the products table (that has prices), you can also get the total amount..




and if you still want to do it the wrong way (store it all in one field in the invoices table), than just serialize() the array with products, and unserialize() it when you get it out of the DB.

Reply With Quote
  #7  
Old November 17th, 2003, 04:08 PM
postalcow postalcow is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Ford CIty, PA USA
Posts: 1,267 postalcow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to postalcow
RE: Best way to save data question

Zombie,

NOW THATS WHAT I WAS LOOKING FOR!!!

That my friend is the best way.

Thanks

Reply With Quote
  #8  
Old November 17th, 2003, 04:48 PM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 4
Send a message via Yahoo to nazly
RE: Best way to save data question

Great.. Zombie.. You just cleared few doubtful minds in here.. I will stick to the right way..

Reply With Quote
  #9  
Old November 17th, 2003, 05:47 PM
prycejones prycejones is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 87 prycejones User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 44 sec
Reputation Power: 3
Send a message via ICQ to prycejones
RE: Best way to save data question

I agree with zombie.
I know there are many ways to do many things (specially in PHP!)
but the idea mentioned by zombie is the way.

Can I add a small caveat - which has bitten me on occasions.
Personally I would keep the price of an item in the item.detail file and the price charged in the invoice.detail file. Normally this would be the same price as the price on the item.prices file BUT there can be occasions when you get this scenario...

Invoice.Header:
Number=1234 Cust=SMITH1 Date=etc.etc

Invoice.Details:
Item#=AA11 Description=House Bricks Price=10.00 Qty=100
Item#=AA11 Desription=House Bricks FREE Price=0.00 Qty=10

IE Buy 100 get 10 free.

The operator may want to bill some more of an item for free or at a discounted price.

Also this is another reason not to use the item.number as a non-duplicate key.

Hope I have explained myself here - do you get what I mean ~Cow?

HIH

รพ

Reply With Quote
  #10  
Old November 17th, 2003, 05:58 PM
postalcow postalcow is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Ford CIty, PA USA
Posts: 1,267 postalcow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to postalcow
RE: RE: Best way to save data question

Quote:
Hope I have explained myself here - do you get what I mean


Yes I did and that makes sense. Thanks Price, I love this forum. The way I was going to do it was painfull at best and added an extra 500 lines of code.


~cow

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesProgramming Theory > Best way to save data question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek