golem Posted April 24, 2007 Share Posted April 24, 2007 Hi , I try to get data from tehree tables. any reason why this does not work? (All the php variables are OK) Thanks! " SELECT users.name, users.phone, users.email, user_books.bookTitle, user_books.bookPrice, user_hats.color, user_hats.pattern FROM users, user_books, user_hats WHERE users.login = '$login' AND users.password = '$pw' AND user_books.user_id = '$userID' AND user_hats.user_id = '$userID' "; Quote Link to comment https://forums.phpfreaks.com/topic/48399-how-to-select-data-from-3-tables/ Share on other sites More sharing options...
bubblegum.anarchy Posted April 24, 2007 Share Posted April 24, 2007 The three tables must be joined with something like this: WHERE users.user_id = user_books.user_id AND users.user_id = user_hats.user_id Quote Link to comment https://forums.phpfreaks.com/topic/48399-how-to-select-data-from-3-tables/#findComment-236670 Share on other sites More sharing options...
golem Posted April 24, 2007 Author Share Posted April 24, 2007 Thanks but I can't get it to work. its working with two tables: " SELECT users.name, users.phone, users.email, user_books.bookTitle, user_books.bookPrice, FROM users, user_books, user_hats WHERE users.login = '$login' AND users.password = '$pw' AND user_books.user_id = '$userID' "; Quote Link to comment https://forums.phpfreaks.com/topic/48399-how-to-select-data-from-3-tables/#findComment-236684 Share on other sites More sharing options...
bubblegum.anarchy Posted April 24, 2007 Share Posted April 24, 2007 Where have you incorporated the code I posted? Quote Link to comment https://forums.phpfreaks.com/topic/48399-how-to-select-data-from-3-tables/#findComment-236729 Share on other sites More sharing options...
fenway Posted April 25, 2007 Share Posted April 25, 2007 Better yet, use proper JOIN syntax: SELECT users.name, users.phone, users.email, user_books.bookTitle, user_books.bookPrice, FROM users INNER JOIN user_books ON (users.user_id = user_books.user_id) INNER JOIN user_hats ON (users.user_id = user_hats.user_id) WHERE users.login = '$login' AND users.password = '$pw' AND user_books.user_id = '$userID' Quote Link to comment https://forums.phpfreaks.com/topic/48399-how-to-select-data-from-3-tables/#findComment-238583 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.