Solved

Testing Conditions to set status on the fly

Posted on 2012-12-26
6
174 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 109

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 109

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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 109

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

808 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