Okay – so I run into this every once in awhile and I usually code around it, but I decided on this cold day in January (-18° below at 7am) that I was going to get this working the way I want it to be!!!
When I google this issue it just loops around and around in a big circle – very frustrating – so when I got it working I decided to put it here – mostly so I could find it!!! 🙄
SITUATION:
I have a form where the information is then put into an sql table.
On this form is a dropdown selection box – being a good data steward, I am only recording 1 character for each choice. However, when displaying the completed list of items that have been entered, I would rather display the actual description rather than the “value” of the dropdown.
Seems like a simple thing – right?!
So, what I wanted to do is when I am looking thru the recordset of the database, I want to have an array that has a cross-reference to the Value that is stored in the Category field in the database.
Seems simple enough – but every reference I could find to arrays in PHP you use the index number to find and display the item in the array. I went thru 6 pages on google to finally find one that references it using the item not the index number. Kudos to this place.
MY SOLUTION:
In my listing file, I created this array (this is the information used in the form – shown above):
$catList = array( "F"=>"Food", "L"=>"Live", "E"=>"Equipment", "P"=>"Plants", "M"=>"Media", "T"=>"Tank", "R"=>"Large Item", "O"=>"Other", );
Then, to do the lookup in the array:
$catList[$row[‘category’]]
$row is the array of information that is being pulled from the database, category is the the field from the database that holds the info from the submitted form.
Well, now the list looks a whole lot better:
BEFORE | AFTER |
![]() |
![]() |