Solved

Testing Conditions to set status on the fly

Posted on 2012-12-26
6
173 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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.

786 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