I'm working on an app and lets' say it's a database of cars. For each car I want to list the engines that came with it. I am thinking of creating two columns in a mysql table. The first column will be the car and the second column will be called engines. Because there could be one or more engines I was thinking of inserting the different sizes of engines delimited by a Pipe(|) 2.5liter | 3.1liter | 3.9 liter When I display the car and engines I just will have to split on the | to read the engine sizes. Is this the normal way to handle when items have a variable amount of attributes ?
You can do it this way but your database will not be normalized. What I would do? Create a table Cars id, car_name , model and other attributes etc Create Engine Table id, engine_desc and other attributes etc. Create Car-Engine table car_id, engine_id (from Car and Engine tables) Better way of doing relational db programming.
If you use the explode("|", $datafromsql); function, you are doing it alright. It will create an array for you, and you can then easily read the engines. I use it often, the explode function. EDIT: you could take jazz's idea too
This will help you in search pages, for example, user wants to search for all the cars with 2.3 engine..!! You can create many pages which will be good for SEO also (given that you are creating a website out of it...)