PHP + MySQL dificult code

Discussion in 'PHP' started by afonseca, Jan 31, 2007.

  1. #1
    Hi All!

    I have a PHP + MySQL dificult code (for me anyway..).
    I have a ecommerce site with a table of products.
    Now I want to create a new table with a list of stores where clients can find near home those products. In a limit situation I can have a list of all products indexed in one store (and the products list is increasing everyday...).
    My idea is to develop 3 tables:

    Products
    +----+-------------------+------------------------------------------+
    | id | name | description |
    +----+-------------------+------------------------------------------+
    | 1 | xxxxx | aasa... |
    | 2 | vvvvvv | asasasasas... |
    +----+-------------------+------------------------------------------+


    Stores
    +----+-------------------+------------------------------------------+
    | id | store | address |
    +----+-------------------+------------------------------------------+
    | 1 | aaaaa | street1... |
    | 2 | bbbbbb | street2... |
    +----+-------------------+------------------------------------------+



    Linking stores with products
    +----+-------------------+------------------------------------------+
    | id | store id | products id |
    +----+-------------------+------------------------------------------+
    | 1 | 1 | 1;2 |
    | 2 | 2 | 2 |
    +----+-------------------+------------------------------------------+

    Can I implement this with PHP? I mean how can (if I can) place several ids in a field? and how can I do the query in order to list the products inside a store?
    Hope that I made my self clear. If not please do not hesitate to request further information.
    Thanks in advance

    António
     
    afonseca, Jan 31, 2007 IP
  2. jumpenjuhosaphat

    jumpenjuhosaphat Peon

    Messages:
    229
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    In your products table you will need to add a quantity field, and a store field. The quantity will show how many products are in stock at the store in the store field. You will have the same product in multiple rows in the table, but retrieving all of the information is a matter of a simple query.
     
    jumpenjuhosaphat, Jan 31, 2007 IP
  3. Perrow

    Perrow Well-Known Member

    Messages:
    1,306
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Let's just say no, he does not.

    Afonseca, your on the right track, your link table should however hold just two fields, product id and store id. Database theory does look down on fields holding non singular values, they make it hard to formulate resource efficient select statements.

    Your link table is whats called a many-to-many relationship between stores and products (ie a store has many products and a product can be sold in many stores).

    As for php code to do this you do need to read up on php/mysql programming but it's not that hard to do.
     
    Perrow, Jan 31, 2007 IP
  4. afonseca

    afonseca Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for fast reply!

    jumpenjuhosaphat
    I dont want stocks involve. Like Perrow said I just want a many-to-many relationship between stores and products (ie a store has many products and a product can be sold in many stores).

    Perrow
    "you do need to read up on php/mysql programming but it's not that hard to"
    Should I search for "many-to-many relationship" php/mysql programming?

    António
     
    afonseca, Jan 31, 2007 IP
  5. Perrow

    Perrow Well-Known Member

    Messages:
    1,306
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    140
    #5
    Just php/mysql programming should suffice for now.
     
    Perrow, Jan 31, 2007 IP