1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

I need help with a SQL query

Discussion in 'MySQL' started by chas.valespurifoye, Nov 29, 2012.

  1. #1
    I need help with a SQL query here's the logic:


    I have a web app that allows a person ( Clients ) to book another person ( techs ) for an event.
    example:
    You have an event you need a photographer on 12/01/12 from 9:00 AM to 3:00 PM, when you search for photographers I need to show all available photographers on that date and time.


    Table structure:
    Whenever you're booked for a gig that info is placed in a table 'booked' you can also input dates you are not available and it will also populate this table.


    The query needs to search the 'booked' table and find all the techs available. If that tech is available I then need to pull that techs info from another table. The problem I'm having is if I have 3 events booked for 12/01/12 but not between 9am and 3pm I show up 3 times.
    I don't know if the logic behind my approach is wrong or what but any help is appreciated. I have my query below.




    SELECT bac_members.username, bac_members.name, bac_members.trade, bac_members.expr, bac_members.city, bac_members.state, bac_booked.start_time, bac_booked.end_time, bac_booked.eventdate, bac_booked.event, bac_booked.confirmed
    FROM bac_members
    INNER JOIN bac_booked
    ON bac_members.username=bac_booked.user AND bac_members.trade='$position' GROUP BY bac_members.username
     
    chas.valespurifoye, Nov 29, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    Booked should have a field for tech.id, so you won't have the same tech booked for the same time slot 3 times. You select WHERE the tech.id is the tech you're looking for and the time slot is the one you want (probably using fixed-width slots, like 15 minute slots, 1 hour slots - whatever the most common or smallest [your choice - the logic will be different] usage is.)

    Design the program first (not 'write the program', design what the program is doing - in English), then design the database (again - in English). Once you have everything designed (you'll see the bugs you're designing, and you can easily change things to get rid of them), start writing code. If you start by writing code, you'll end up with spaghetti - assuming it even works.
     
    Rukbat, Nov 30, 2012 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    You use SQL queries to talk to SQL databases. You have to be more specific if you want more information. Your question is like "tell me about sentences".
     
    Rukbat, Dec 12, 2012 IP