PHP MYSQL - a lot of data in one column

I need to store 100-200 data in mysql, data to be piped.

any idea how to save it to mysql? should i use one column or should i be doing many columns? I don't know exactly how many data users will be entering.

I made a form, it stopped at the part where I need to save a few data.

Does anyone know how to store multiple data in one column or is there an alternative way?

Please help me..

Many thanks

0


source to share


3 answers


You have to implement your table with data source id. This ID will be used to group all this same data, so you don't need to know how much you have.

Columns and table data can be customized as follows:

sourceID        data
--------        ----
       1         100
       1         200
       1         300
       2         100
       3         100
       3         200

      

When you query the database, you can simply load all data with the same source code. With the above data, the following query would return two pieces of data.

SELECT data
FROM dataTable
WHERE sourceID = 3

      

If you have multiple tables, you need to link them to each other using syntax JOIN

. Let's say you have a main table with user data and you want to associate all that input with each user.



userID    userName    otherData
------    --------    ---------
     1         Bob          xyz
     2         Jim          abc
     3         Sue        lmnop

      

If you want to combine data from this table (userTable) with data from dataTable, use a query like this:

SELECT userID, userName, data, otherData
FROM userTable
LEFT JOIN dataTable
ON userTable.userID = dataTable.sourceID
WHERE userTable.userID = 1

      

This query will give you all the data for user ID 1. This assumes that the original ID in your data table uses the user ID from the user table to keep track of who owns the additional data.

Note that this is not the only JOIN syntax in SQL. You can read about other types of joins here .

+4


source


If you have a form where this data is coming from, save each input from your form to a separate column.

Look for relationships in your data: it looks like you have a has many relationship, which indicates that you might want a link table where you could perform a simple join query ...



Storing multiple data in one column would be a nightmare for queries and updates, if you don't store XML, an event would give me nightmares ...

+1


source


Sounds like you want a join table. Only have the data you need in both tables, create a third table with the ID of both tables, then it doesn't matter if you need 100, 200, 300 or more.

+1


source







All Articles