Click here to Skip to main content
15,038,237 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how can i store multiple select value using comma in database and retrieve them in php


What I have tried:

could you please give me any solution
Posted
Updated 31-Oct-20 2:40am

1 solution

Basically, don't.

It's a poor idea to store anything in CSV inside a DB column, because SQL is monumentally poor at string handling - so adding, removing , and altering items from the column string becomes a PITA.

Instead, create an extra table which links you "new values" to to old table. For example, if this was an invoice sytem, youd have an Invoices table and an InvoiceLines table:

Invoices:
ID
CustomerID (Foreign key to Customers table)
DateIssued
DateDue
NetTotal
VATTotal
TotalDue

InvoiceLines:
ID
InvoiceID (Foreign key to Invoices table)
ProductID (Foreign key to Products table)
Quantity
UnitCost

You can then add, remove, alter whole row from the InvoiceLines table as needed, and fetch the Line data for a specific Invoice with a trivial JOIN.

It may seem like more work to set up - and it is, a little - but it's a whole load less work than doing anything useful with the CSV data would be later!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900