can any one explain how generally address taken from user stores in database...does that will be either of these or not
taken each line as different parameter from user using different text boxes and stores in different columns of a table
taken as one text area stores in a column of a table with field name address
Taken as text area and stores by parsing that text and storing in different columns.
I assume address contains Door no,street name,area,city,country,zip code
and also tell me which among the above is preferable way to store...
Think about what you want to do with the information to begin with. If you have no real use to ever use the addresss, but you are displaying it purely for informattional purposes, then you can just provide a single textarea.
If however, you are maybe going to be providing some GeoCoding service which needs to be able to pinpoint there address, then you will most certainly need: Postcode, City and Town etc.
When I store address information, this is what my schema looks like:
Address
City
StateProvince
zipPostCode
countryId
woeId (as per http://developer.yahoo.com/geo/geoplanet/data/ )
It is obviously just up to you. Think about how you need to best make use of the data, and make it as easy to enter as you require.
Related
Firstly, here is the relationship between the relevant tables.
I'm developing an Access frontend to serve as a CRUD for an underlying MySQL database, and I'm most of the way there for properly representing and interacting with the tables in a many-to-many relationship. I followed the instructions in this tutorial and my form is mostly functional. But the tutorial example is limited in that the third table in the relationship (in my case, Addresses) is static, and cannot be changed from the form.
Here's how my form looks currently. When adding a new entry in the people_has_addresses subform, if I wish to add an address which already exists in the addresses table by entering its ID into the addresses_addressID column, everything works. The rest of the columns automatically load in the address, and people_has_addresses automatically populates a new row with this unique combination of PersonID and AddressID. The problem comes when I want to create a new address on the fly, add it to the Addresses table, and populate people_has_addresses with this new combination. If I free-form type a new address into the subform and hit enter, I get the following error: "The Microsoft Access database engine cannot find a record in the table 'addresses' with key matching fields 'addresses_AddressID'."
My question is, what do I need to do in order to allow the creation of new rows in Addresses? Ideally working the way I describe above. I feel that I'm close to getting this right, but don't know what to do from here.
Ok, so the combo box in that row lets you select a given address. You not really described that if you have 10 address,which one you want to appear say in a mailing list or what not. What you could do is add an extra column to the table where you shove in (save) the address id, and add a "default" check box. Then you can have a query with the default Address column = true to only pull the one address for mailing etc. So in this example, I do have a check box to select which out of possible many address are to be used by default. And we could add another column for home, business, holiday location or whatever. That way you can categorize the address to what it is.
However, the issue and your question is of course how to add a new address?
There is as many ways to do this as their are flavors of ice cream. In other words, it up to your creative mind. One way would be to use the combo box not in list event. So if you typed in a address id that don't exist, you could be prompted to enter it. However, users should never have to see, know, or use some silly "id" during data entry. Users in fact should never even see PK or FK id's during use of the application.
I would suggest you next to the combo box that lets you select a address is place a button to add a new address. You could use a graphic image like a + sign. So, they can use the combo box to select an existing address, or click on on the + button to add a new address. What the code behind the button would do is launch a form to edit the address, but launch the form in add mode. And when you close/save the form, then the code could/would stuff in the PK id of the new address you just added into the FK Address_ID column for the address.
And in the interest of cruelty to animals and your users? They should not need to know or see or type in some "number". The combo box can hide the first PK column. So when you select a given address (in this example hotel, but it could be just a address) you display the name. So, users in place of expanding the combo box can just start typing in the hotel name. To be fair, with address, you really don't have a "name" to type in, so your case is somewhat different. In most cases the thing you are selecting has some name, or part name/number, or in our case a Hotel Name.
Note that the sub form is based on a query that joins in the other columns. So, when they crack open the combo box, they are in fact selecting a PK. So like magic (and without code), then the city,province, description columns automatic display from that other table.
So the form would look like this:
In above, we selected several hotels. However, note the check box as to which address to use, since we might have several, but for printing a letter or envelope, then the check box will determine which address will appear.
And in the above, if we don't find or have a Hotel (or address) we want to use, then we can hit the + sign beside the combo box. That would launch up a nice single form layout to enter a new Hotel (or address). As noted, how you setup your UI to work is quite much a open canvas. One great way to get ideas is to look at other software you use. So, how do you add multiple address to outlook users? So, a gazilion ways and ideas exist as to how you want to do this. It not really how to do this, but HOW YOU want this to work, since you can design this to your hearts content to work quite much anyway you want.
So, the PK id should not be exposed here. Users can't care or know about such things. I mean, as I am typing this response, no doubt the SQL server that drives stack overflow generated a new number for this post - but it not a user thing, only a developer thing to care about.
Ok, so we build that sub form. The table driving that sub form is only
ID (PK)
Customer_ID (FK to parent form driving this)
Hotel_ID (FK to hotel - or in your case address)
DefaultAddress (true/false column)
And as noted, we should add ONE MORE column that sets the address as the default address to use.
eg: default address.
. All of the other columns display as a result of a left join. (a left join for this sub form is VERY important).
Now, if a hotel is not in our list of choices, then the user can simply hit the + sign beside the combo box, and we pop up a nice form to edit/add a new hotel. And take well note that when you use outlook, an accounting system, or just about any software? You not seeing and typing in PK id values - that only really for you the developer to see, and end users should never see or have to deal with actual PK numbers.
In a example database I store a reference to different contact addresses for a user.
| userid | contactAddress | sendNotification | sendWithDetail |
I would like to store is different types of contact address such as email or a phone number in the contactAddress field. The other fields in the table will remain consistent regardless of type of address, but I do want to be able to put tight validation on all fields.
What are the options to create this in a mySql Database?
I am not in a position to change my database type.
I have scoured google but I think there is a term name that I don't know as I cant make any headway. Any kicks in the right direction much appreciated.
You have answered your own question, store a value to indicate type and then the value itself
The options I have found (but cant seem to find any more info on) are
Add an extra field to represent type, and just store the address in a text regardless of type. This makes validation harder but keeps things simple
Make a different table per type of address, then store the key within the address table. lets you have more fields per type, but will make some complicated key links
i am creating a search functionality for a website where i need to take the user's full address from an input e.g "Address 32, City,Region,Country, Postal Code"(no necessary with this order) and return the available restaurant that are around the area.
I have a table "address" where there is a field for each of the above elements.
I was thinking of concatenating the users address from the database and compare it with the user's input by help of SQL REGEXP.
Is there any other approximate SQL search that can give me that or can you suggest me a different approach?
A friend suggested using (http://www.simonemms.com/2011/02/08/codeigniter-solr/) however with a small research on it the problem still remains.
Trouble with concatentating the address together in SQL is you will miss out on it using indexes. Hence it will be slow. Added to which if you do not know the order of the input elements the chances of it matching what is concatenated from the database (is a likely different order) is slim.
I would suggest for much of the address items, split them off into different tables (ie a table of regions, another of countries, etc) and just store the ids in the columns in the users table.
For a search, identify which of the search fields go with which actual field then join on those to find the real address.
Also means you can identify typos more easily.
I have a 'strategy' question.
Thing is, we have a table of customers' addresses and customer orders. Structure is something like (just an example, ignore filed types etc.):
Address
id INT
line1 TEXT
line2 TEXT
state TEXT
zip TEXT
countryid INT
To preserve historical validity of the data we are storing those addresses in a text field with orders (previously it was done by reference, but this is wrong because if address changes all old orders change delivery address too, which is wrong). E.g:
Orders
id INT
productid INT
quantity INT
delivery_address TEXT
delivery address is something akin to CONCAT_WS("\n",line1,line2,state,zip,country_name)
Everything is nice and dandy, however it seems that customers need an access to historical data and be able to export those in XML format and they want to have those lines split up properly again. Because sometimes there is no line2 or state or zip or whatever, how can we store this information in a way that we can then decipher the 'label' of each line?
Storing as JSON encoded array was suggested but is this a best way? I thought about storing it as XML... or maybe create those 6-10 extra columns and store address data with every order? Perhaps some of you guys have more experience in dealing with this kind of stuff and be able to point me in the right direction.
Thanks in advance!
Personally I would model the addresses as a single table, every update to the address would generate a new row, this would be marked as the current address.
I guess you could allow deletes if there are no related orders, however it would be simpiler to mark the old record as inactive.
This will allow you to preserve the relationship between orders & addresses,
and to easily query the historic data at a later date.
see the wikipedia entry for slowly changing dimensions
The best way IMHO is to add history to the address-table. This will cause extra elements to be added for its key (say address_id and {start_of_validity, end_of_validity}) The customer id than becomes a foreign key into the customer table. The orders table references only the address_id field (which is "stable" in time). New orders would reference the "current" row in address.
NB: I dont know json.
You should store those as 6-10 extra fields, just like you do in the current address. You see, that way you have every piece of information at hand, without having to parse anything.
Any other approach (concatenation, JSON, XML) will make you have to do parsing when you need to access the info.
when you say "previously it was done by reference, but this is wrong because if address changes all old orders change delivery address too, which is wrong", it was not that wrong ...
Funny, isn't it?
So, as proposed by others, adresses should (must?) be stored in an independant table. You'll then have different address types (invoicing, delivery), address status (active, inactive) and a de facto address history log ...
In order to be able to utilize the address data for future uses you will definitely want to retain as much metadata (meaning, fields such as Address, City, State, and ZIP). Losing this data by pulling it all into a single line looks simpler and may conserve a small amount of space but in the end is not the best method. In fact, breaking it apart is very difficult--much like separating out first and last names from a generic, one-size-fits-all "name" column. Having the data stored in complete entries, utilizing 6-10 new fields (as mentioned) is the best way to go.
Even better would be standardizing the addresses (at least the US addresses) when they are first entered. That would ensure that the address is real and deliverable and eliminate shipping issues in the future. My thoughts, always retain as much of the data as possible because storage is cheap and data is valuable.
In the interest of full disclosure, I am the founder SmartyStreets. We provide street address verification.
I'm planning a database who has a couple of tables who contain plenty of address information, city, zip code, email address, phone #, fax #, and so on (about 11 columns worth of it), a table is an organizations table containing (up to) 2 addresses (legal contacts and contacts they should actually be used), plus every user has the same information tied to him.
We are going to have to run some geolocation stuff on those addresses too (like every address that's within X Kilometers from another address).
I have a bunch of options, each with its own problem:
I could put all the information inside every table but that would make for tables with a very large amount of columns which I'd have problems indexing, and if I change my address format it'll take a while to fix it.
I could put all the information inside an array and serialize it, then store the serialized information in one field, same problem with the previous method with a little less columns and much less availability through mysql queries
I could create a separate table with address information and link it to the other tables either by
putting an address_id column in the users and organizations table
putting a related_id and related_table columns in the addresses table
That should keep stuff tidier, but it might create some unforeseen problems with excessive joining or whatever.
Personally I think that solution 3.2 is the best, but I'm not too confident about it, so I'm asking for opinions.
Option 2 is definitely out as it would put the filtering logic into your codes instead of letting the DBMS handle them.
Option 1 or 3 will depend on your need.
if you need fast access to all the data, and you usually access both addresses along with the organization information, then you might consider option 1. But this will make it difficult to query out (i.e. slow) if the table get too big in mysql.
option 3 is good provided you index the tables correctly.