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' "; 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 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' "; 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? 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' 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
Archived
This topic is now archived and is closed to further replies.