SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I would like to make a field part of a many to many relationship.

    I have the following table called stores

    Code:
        id     store       zip
           1     Market 1    01569
           2     Market 2    01551
           3     Market 3    10468
           4     Market 4    10435


    Zip code table

    Code MySQL:
     INSERT INTO `zip_codes` (`restaurants_locations_id`, `zip`, `state`, `latitude`, `longitude`, `city`, `full_state`) VALUES
        (1, '06001', 'CT', ' 41.789698', ' -72.86431', 'Avon', 'Connecticut'),
        (2, '06002', 'CT', ' 41.832798', ' -72.72642', 'Bloomfield', 'Connecticut'),
        (3, '06010', 'CT', ' 41.682249', ' -72.93365', 'Bristol', 'Connecticut'),
        (4, '06013', 'CT', ' 41.758415', ' -72.94642', 'Burlington', 'Connecticut'),
        (5, '06016', 'CT', ' 41.909097', ' -72.54393', 'Windsorville', 'Connecticut'),
        (6, '06018', 'CT', ' 42.023510', ' -73.31103', 'Canaan', 'Connecticut'),
        (7, '06019', 'CT', ' 41.834247', ' -72.89174', 'Canton', 'Connecticut'),
     
    etc....

    what I want is to create a table which will connect the zip field in the stores tables where one store will be found in several zicodes...


    How would that table would look like?

    Thanks

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,264
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    You'd have something similar to this:

    TableName: StoreZipCodes
    StoreID int
    ZipCodeID int

    Where StoreID is a ForeignKey to the ID on the stores table and ZipCodeID is a Foreign Key to the ID field on the Zip_Codes table
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •