how to save multi-name into one field, and display only one

W

work4u

From my system, it allow product has multi-category, so I need to save
all
category names which one product belong to into one field on a
database,

and record saved like " nameA|nameB|nameC " - seperate by "|".


question 1:

the second time when i update the record for same product name, how to
have a record
like "nameA|nameB"


After multi-category name saved, then, i would like to generate a
navigate name with the link like


home > nameB > name of product


question2:

so how can i retrieved only one name from category field




Please post sample code.


thanks in advance.
 
M

Mark Schupp

Putting multiple values into a single column is generally considered very
bad database design. It results in the problems you are encountering now.
You will also be unable to use simple SQL to do things like extract all
products belonging to a particular category.

You will have to use script code to extract the value that you desire once
you retrieve it from the database. Look at the VBScript Split function this
can return an array from which you pick the desired element. IE:

aName = Split("nameA|nameB", "|")
aName(0) would contain "nameA"
aName(1) would contain "nameB"

If it is at all possible you should restructure your database to not have
multiple values in a single column. Something like:

table products (product_id,...

table productnames( product_id, productname,...

For each new name you would add an entry to productnames.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top