Simple question from a newbie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Simple question from a newbie

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Simple question from a newbie

Post 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']];
 
(#10850)
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Re: Simple question from a newbie

Post by micknc »

I knew it would be something simple.
Worked perfectly.

Thanks
Post Reply