Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array in a Table

Status
Not open for further replies.

TGrahmann

Programmer
Feb 19, 2015
43
US
Hi, I'm working on an application, and I need to be able to be able to store and (easily) edit array data to/within a table. For instance, a field name may be "units" and I would need to store multiple values from another table to that field as some sort of array, for instance a user may enter numbers such as "401" but later add another such as "510". I need to be able to add an indefinite number of values to this field. Any help is greatly appreciated!
 
Hi,

Rather than a field named UNITS, make a field named, for instance, CATEGORY, and a field named CAT_VALUE.

Then when you have UNITS with a value of “401”, enter “UNITS” in CATEGORY and “401” in CAT_VALUE. Then “WIDGET” and “702” etc.

When you want all the UNITS values, run a query...
Code:
SELECT CAT_VALUE
FROM [i]YourTableName[/i]
WHERE CATEGORY=“UNITS”



Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
You can store serialized arrays in a mysql text field type. Serializing takes an array and turns it into a string you can store in a DB table.

If using PHP for instance, you can call the serialize and unserialize functions to turn an array into a string you can store in a single table value.

When you unserialize it, you can have your code use it as regular array, and add and remove entries, and then serialize it, and save it back to the table.



----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top