The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Substring headaches Re: Substring headaches


Hi there – looks like based on what you’re trying to do you may benefit from using 2 more tables in your database. Specifically – you could build these tables:

**ware** & **profileware**

**ware** should have an ID and a VARCHAR field for the name of the ware

**profileware** should have an ID and a wareID and a profileID and a TINYINT called _isbuying_ that is 1 for buying and 0 for selling (or equivalent)

**ware** will keep track of all of the wares available, should just be the 126 listed out. and **profileware** will keep track of the relationship between the profile (user) and the ware. so if my profileID is 5 and i want to buy iron (wareID: 1) and sell sheep (wareID: 4) there should be two rows in profileware for me:

ID: 1, profileID: 5, wareID: 1, isbuying: 1
ID: 2, profileID: 5, wareID: 4, isbuying: 0

then in your HTML markup – name each of the wares something like this:

The value corresponds to the ID of the ware, and ALL of the checkboxes can have the same name “buyware[]”

When the user saves the data, you will have an array of all of the wares they have selected. In the DB erase all of the profileID records from profileware and insert new records for each of the wares they have selected by doing a foreach on $_POST – also be sure to keep track of whether they are buying or selling so buying checkboxes are called name=”buyware[]” and selling are name=”sellware[]” – etc.

Is this making sense? Then read into MySQL JOINs and reap the rewards of relational databases! :)