jeudi 22 juin 2017

How to handle multiple value selections in PHP and MySQL

I recently took an online PHP / MySQL course, and as a way of practicing I promised a friend of mine to make some kind of stock keeping site for his paint shop.

Unfortunately, I quickly ran into a problem. Let me explain the situation.

First up we have the product/paint itself. Let's assume we have a paint table, with: paintID: INT, AI paintType: varchar (e.g. metal, primer, water-based, etc.) paintPrice: INT (e.g. 10, 15, 20) paintColor: ???

And I thought of creating a colors table: colorID: INT, AI colorName: varchar (e.g. blue, red, white, transparent, etc.)

Every paint product comes in one or more colors. So I thought of making a section within the product.php page offering all the colors as checkboxes.

While this is simple enough in product_new.php mode,

  • how can I store the selected colors via PHP in the MySQL database once he presses submit (and what type to give to the paintColor column)
  • how can I retrieve/show all the possible colors with the chosen ones selected once in 'read-only' or 'update' mode of the product page

I would appreciate any (detailed) assistance/guidance on how to tackle this issue with PHP and MySQL.

Kind regards,

Erlend




Aucun commentaire:

Enregistrer un commentaire