Solved

Testing Conditions to set status on the fly

Posted on 2012-12-26
6
170 Views
Last Modified: 2012-12-26
I have a table that holds orders.  One order can take up multiple rows, and each item can have its own status within an order.

What I'm trying to do is figure out a way to look at each row, and if all the status' equal 1 to code the order status as 'Placed'  If there are two items marked as shipped but one as placed, the order status would be In Progress.  Similarly, if all item status' equal Shipped, then the whole order is marked as shipped.

Not sure where to start on this.
0
Comment
Question by:t3chguy
  • 3
  • 2
6 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 38721833
I'm fairly certain the right place to start is to make a Google search for this exact set of search terms and begin by reading the thoughtful arguments on both sides of the issue:
Should I Normalize My Database
A normalized data base will not have data structures that lead to ambiguity or that "where do I start" feeling, I promise!
0
 
LVL 1

Author Comment

by:t3chguy
ID: 38721841
So you're saying that my the way I've structured the data is not good?  How could it be better organized?
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 38721908
This is just a quick guess (you really need a DBA to advise you).  No order would take up more than one row -- that is the canonical element and it should have a row of its own.  The table of orders would have a separate junction table that joined each order to the items within the order, and a separate junction table that joined the items to shipping and payment status, etc.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:t3chguy
ID: 38721921
Thanks, Ray, sometimes, I think taking shortcuts and adding tables isn't always the best solution, but in reading more and more about normalization and understanding your flow from your previous post, I'm starting to see that that is not always the case.

I'm going to restructure my table and have the following structure:

mk_indiv_orders
mk_indiv_items

So knowing that now, would it be better to help answer my initial question regarding checking each item status and from that updating the overall order status?
0
 
LVL 21

Accepted Solution

by:
Kim Walker earned 500 total points
ID: 38722116
Is it safe to say that there are only two values for the status of an individual item, placed or shipped? If that is true, you could use the DISTINCT modifier to select the distinct values for the status of all the items in the order. If your query result has two rows, then some items are placed and others are shipped and the order is "in progress." But if all the items are placed or all the items are shipped, only one row would be returned and the order status could take on that one distinct status.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 38722510
Glad you found a solution.  Sorry I couldn't help further, but I went to see the movie Django with my son, and it was voted Excellent by two generations!  Best regards and Happy New Year 2013, ~Ray
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now