#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Red face SQL (Simple?) REQUEST PROBLEM - Urgent


    Hello THE WORLD ,

    Yesterday, I spent a nice part of the whole day torturing my mind to try to find a solution to my problem.
    If you could give your advice this would not refuse .

    I explain :

    I have "products" which is a table which contains the lines:
    product_id / date_in / date_out/ id_room

    and another table " rooms " that contains :
    id_room/ photo / city / condition

    and I try to find a solution to the question that seems to be the Evrest today for me (I am noob )
    How to , when I 'm on a page product and I have aa _GET in the URL , (exemple: reservation_details.php product_id = 1) make a request to SQL for have the other products who are in the same city and in the same date?

    I try lot of codes and here is the last one I made ​​:
    code:

    Code:
     
    SELECT p.product_id , s.photo
    FROM products p, rooms s
    WHERE.id_room IN (
         id_salle SELECT FROM rooms WHERE city IN (
               SELECT city FROM rooms WHERE id_room IN (
                     id_salle SELECT FROM products 
                     WHERE product_id = ' . $ _GET [ Product_id ] .')) )
    AND WHERE product_id < > ' . $ _GET [ Product_id ] . '
    = 1 AND p.condition
    ORDER BY p.date_in


    Of course with : AND WHERE product_id < > ' $ _GET [ product_id ] . '. I have a SQL error, but as I try to exclude the product which is in the _GET ... I do not know what to do ...
    When I remove "AND WHERE product_id < > ' . $ _GET [ Product_id ] . ' " The product that I 'm still appears and others who are not in the same city ... My short code is zero and then I lost it must ultimately be quite simple ...
    What you say ?
    Thank you for your support.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,056
    Rep Power
    9398
    Use JOINs.

    1. Start with the product table and target the product you're searching on.
    2. Then JOIN in the corresponding room table.
    3. Then JOIN in the room table again that matches the same city. You might want to exclude the same room you started with, I don't know.
    4. Then JOIN in the products table on that second set of rooms, making sure to exclude the product you started with. This is where you get the matching product information from.

    That'll take care of the "same city" problem, but I'm not sure how you want to deal with the "same date" since it's apparently a range (comes in as a start and end date). Same date range? Overlapping dates?
  4. #3
  5. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,173
    Rep Power
    4274
    Originally Posted by requinix
    Overlapping dates?
    the following two threads are mandatory reading...

    http://forums.devshed.com/mysql-help...me-819034.html

    http://forums.devshed.com/mysql-help...od-936024.html
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Even more important: The 6 worst sins of security.

    No, letting anybody on the Internet write directly into your query is not a good idea.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0
    Hello,
    And thank you to all for have answer to me.
    As you could see I am not very good in sql language, and I really need the request before tuesday.
    Could you give me it please? I should be very simple but for me it's the Everest...
    I am in the ****.. lol
  10. #6
  11. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,173
    Rep Power
    4274
    Originally Posted by MuSQLor
    Could you give me it please?
    not until you clear up the requirements for date matching

    and maybe not then, either

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo