Solved

Testing Conditions to set status on the fly

Posted on 2012-12-26
6
171 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 22

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

920 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

13 Experts available now in Live!

Get 1:1 Help Now