Page 1 of 1

Simple question from a newbie

Posted: Sat Jan 26, 2008 10:01 pm
by micknc
At least I am guessing this is simple. I have been writing a very basic page that returns results from MySql and I have learned a lot but I am stuck on one of my goals for the page. Here goes:

One of the fields is a status field (S, P, V) I figured out how to limit those fields when I search but I need to also be able to add a status result to my results page. Basically if status=P then echo "Order Invoiced";

I haven't been able to dig up any tutorials for this one so I have resorted to begging.
Thanks guys

Re: Simple question from a newbie

Posted: Sat Jan 26, 2008 10:15 pm
by Christopher
You could have another table with the code and text descriptions and you could join the two tables. The table would be like:

table status_codes:

Code: Select all

id         description
S        Whatever S is
P        Order Invoiced
V        Whatever V is
And the SQL would be:

Code: Select all

SELECT * FROM orders JOIN status_codes ON order.status=status_codes.id WHERE ...
Or you could do it in PHP with an array:

Code: Select all

$status_codes = array(
'S' => 'Whatever S is',
'P' => 'Order Invoiced',
'V' => 'Whatever V is',
);
 
echo $status_codes[$row['status']];
 

Re: Simple question from a newbie

Posted: Sat Jan 26, 2008 10:41 pm
by micknc
I knew it would be something simple.
Worked perfectly.

Thanks