Retrieving a 2-D Array from DB

Hi Experts,

I am writing an application that each sales agent has their own rates for each product with pre-defined categories. For example, my MySQL table has the following fields

agent_id
product_id
family
adult
senior
child

When I query this table my WHERE clause will provide the agent_id.

Since there are multiple of products, I will get back multiple of rows, and I am doing this via PDO.

My question is, is it possible that I return this as a two-dimensional array, for example:

$agent['roller_coaster']['family'] = 49.99, where of course, roller_coaster is my product id?

Thank you
APD TorontoSoftware DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
If you are just starting your implementation, can you change your db layout?

I would use below where you have a product table that contains an id, type id and name.  An agent table with the id and name.  Product type (adult, child, family).  Then each product would have a unique id linked to a type.  Finally, a price table that would contain the product_id, agent_id and price.  If you have 3 products with 10 agents each with their own unique price, you end up with 30 rows of data.  Even if some agents have the same price, you still end up with 30 rows of data.  Select the price by selecting the product_id and agent_id.

my 2cents.

PRODUCTS
product_id
product_type_id
name

AGENTS
agent_id
name

PRODUCT TYPE
product_type_id
name

PRODUCT PRICE
product_id
agent_id
price
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.