Here’s my problem…
I am making a client managing interface that saves values to SQL
I am using SQL/PHP/HTML/JQUERY/CSS etc…
Everything is ok when i all the information are entered once for each client.
ie. each client has 1 or 2 phone numbers, one address, etc.
The problem appears when i want to store say multiple receipt numbers of a client.
Or ie. multiple orders of the same client.
I could start with one but through time i might need to store 100.
What is the best practice to do this?
I thought of storing the ID’s separated by commas in a single text record in SQL
Then retrieve the values, separate them and serve them.
What is the best way to do such thing?
Also, how can i command SQL to add a value to the end of the existing string instead of updating it?
Can i automatically add a column to sql each time a similar record is needed?
You could save it as comma separated values but this is very bad practise and ultimately becomes a pain to maintain.
What you need to have here is SQL normalisation.
For example, in the case of Receipts you have two tables, one for the customer, with a unique id field, and one for receipt which has two columns, customer Id and Receipt Number, so a table for your Customer details:
And another table for receipts:
Then to get all the Receipts for that customer,
And to add a new receipt:
This is a very loose description but I hope it gives you the idea of what you need to do.
Update:
To give you a sample of how this will look, if you have 2 customers in the Customer Table:
And customer 1 has 2 receipts, and customer 2 has 3 receipts:
So the idea is that for each extra bit of information, you only need to add another row. That way you can have 1 bit of information for one customer, and 20 for another, but you don’t need to define 20 spare fields just in case.