phpMyAdmin Online Booking structure help

Discussion in 'Databases' started by VanillaWafers, Jan 21, 2012.

  1. #1
    I am working on my first database driven php script and decided to do an online booking form with a user login ability to return and access their past orders and etc.

    Anyways, right now it is still only in the database design stage. I thought I had something put together properly but when I run a sql statement it is returning improper values.

    This is my structure

    booking-structure.jpg

    Right now I have 2 entries into the database with names of noah and fff. With Noah having 2 bookings and ff having 1.

    When I run the following query
    SELECT `bookinfo`.`userID`, `bookinfo`.`bookDetails`, `userinfo`.`fName`
    FROM bookinfo, userinfo

    it returns results it should not



    userID bookDetails fName
    7 junk noah
    7 junk fff
    7 trash removal noah
    7 trash removal fff
    8 fs noah
    8 fs fff



    It is for whatever reason giving every user every booking detail.

    Noah should have the jobs "junk" and"trash removal" while fff should have fs

    Anything im missing with either the query or the table?
     
    VanillaWafers, Jan 21, 2012 IP
  2. iama_gamer

    iama_gamer Active Member

    Messages:
    404
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #2
    You should use a WHERE condition to link the two tables or else it just matches every entry in the first table to every entry in the second. I cant make out the column names from the screenshot but it should be something like bookinfo.userid = userinfo.userid. It is good to consider using indexed columns for the joins.
     
    iama_gamer, Jan 26, 2012 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    How you word the SQL statement depends on what you want returned. A WHERE clause may work, or you may want a JOIN of one kind or another.
     
    Rukbat, Feb 25, 2012 IP