Property in Spain | Payday Loans | Mortgage Calculator | Football news | Mortgages
Need help with database design for changing features! [Archive] - ZGeek

PDA

View Full Version : Need help with database design for changing features!


cyberwired
07-11-2005, 07:51 AM
I've been trying to think of different ways to do this and I think I just need a fresh thought from someone who might already have done it.
Heres basically what I'm trying to achieve:

Web site is going to list cars online. Will be designed in PHP and mysql
Where I've gotten a little stuck is the car details page.
I want to be able to add features to the cars with a tick box.
Eg ABS Brakes, Air Bag(s), Air Conditioning

What I'm not sure on is how to store it in the database.
I could have a number of fields for every feature and a yes or no as to whether the car has it but when I want to add a feature that will be annoying.
If I could somehow have another table with all the features to choose from and they are stored in a csv style in the other table that would be good, problem with this comes when there are more than 9 items
Eg if I had ID numbers on the features and added these numbers to the Car feature field like 1,3,5,6 it would say that it uses those items.
When it has 1,3,5,10,11,12 though and it could display that alright but when it comes to searching on that that I will have a problem
As in if I searched for all cars that had feature with ID 1 it would pick all cars that had a 1 in the field (so it would get 10, 11, 15 etc)

Anyone got any advise on this?

Spingo
07-11-2005, 12:46 PM
Change your search criteria.

When someone searches for "1", code your PHP script so that it actually searches for ",1," (note the commas - you can replace these with other non-numeric chars if you wish.) You'll also need to ensure that the delimiting character is before AND after the string of numbers as well as delimiting them.

You'll also need to make sure that you have a Full Text Index running on the field that you're searching in for optimal performance.

cyberwired
07-11-2005, 12:49 PM
wicked, second time you've helped me with this site :)
much appreciated spingo, what you do? web design for profession or just as a hobby?

Spingo
07-11-2005, 12:58 PM
What do I do? Better question is what DON'T I do!!!

But seriously, I work full time as a jack-of-all-trades Systems Integration Engineer for a company that implement media monitoring and digital asset management solutions for a fair view businesses and governments. I'm also a partner in 1337 as Hosting, the company that hosts ZGeek among a couple of hundred other sites.

I have done a lot of PHP and MySQL stuff in my day, including coding the ZGeek front page a few years back when vBulletin 3 first came out. I'm currently working on a coding a couple of plugins for vBulletin 3.5 including a trouble-ticketing system and online billing system.

I wouldn't mind doing Web Design full time, although I'm not particularly creative with the visual side of things. Programming backends and functional bits of code would be more of what I'm good at. But I honestly don't think that I'll ever do it full time as I'm too far down the Internetworking Engineer kind of path to do so.

druid
07-11-2005, 07:42 PM
Create one table that has (at least) two columns: feature id and feature name. Create another one that has product (car) ids and feature ids (you do have product IDs don't you?). Only one id pair per row kthx, no CSV bullshit*. Et voilą!


*Using a list like that is not a really good idea. Searches are probably slower and in the long run it's not really extensible. I'm imagining changing features would be awkward too. Overall it's just not good db design. It sounds like at the present time your schema is going to have a lot of redundancy which is BAD.