PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
This field is going to be used for searching only. To normalise it into tables is going to be of no use.
Soon i'm going to have a postcode field, which will be used to find locations close by the search you have input. How would you go about doing something like this.
For example.
I search "NW4"
on the bottom of the page I would put all distinct postcodes close by, such as "NW7","NW6","NW8"
Question would you put one field postcode_closeby and input "NW7","NW6","NW8" into this field for each record. As each record is pulled out, I create an array and see if the values in the postcode_closeby exist. At the end of the page, I manipulate the array.
-- fields
id int(11) autoincrement primary key,
company varchar(255) not null,
area varchar(255) not null
-- data
1, 'co1', 'london',
2, 'co1', 'birmingham',
3, 'co1', 'wolverhampton',
4, 'co2', 'london',
5, 'co3', 'birmingham',
6, 'co3', 'walsall'
This will allow you to search the way you want and give you optimal results. It will allow you to show all companies with a city name in the area AND it will allow you to show all areas near a company.
and it'll allow you to have more companies. Since the number of companies you can pack into a field would be a function of their company and area. Records would be penalized for having more areas or longer company names. That's not a good situation.
The near by postcode will only be used to display at the bottom of every company result. So the user can click through to another postcode for more results on this postcode
The Company could be near one postcode or even more than one.
If its a possibility of one to one or one to many, then would you advise to split the tables.
Just as a question:
What would you do to table structures, where there may not be a one to one or one to many on some records and a one to one or one to many on some records?
One-to-one I generally keep in the same table. There are a few exceptions, but that's rare. The dividing line for me is how frequently is this field needed over that field.
One-to-many are always separate tables. The table holding the many will often not have an auto_increment on it, due to just not needing it for most purposes. So in your case, my version would have two fields: company id and postal code. However, I might have taken a different route given the option.
For example, if I could get a longitude/latitude position for the businesses I could use various geologic translation to calculate what's close, and I can vary what's defined as close. I prefer options where possible.