kagster Posted June 16, 2009 Share Posted June 16, 2009 Hi all, I try to make a search engine that will search on three tables and with multiple fields. Something like this: <form action="search_results.php" method="post" name="findBook"> <p><label>Book title:</label><input type="text" name="BtName" class="field" size="20" /></p> <p><label>Author:</label><input type="text" name="AuthorName" class="field" size="20"/></p> <p><label>Publisher:</label><input type="text" name="PubName" class="field" size="20"/></p> <p class="btn"><input type="submit" name="submit" value="Search.." /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> And this is the three tables that form will search: ----------------------------------- BOOKTITLE BtId (Primary Key) BtName PubId (Foreign Key) Value ----------------------------------- ----------------------------------- AUTHOR AuthorId (Primary Key) AuthorName ----------------------------------- ----------------------------------- PUBLISHER PubId (Primary Key) PubName PubAddress ---------------------------------- I dont know how can make this select. The user needs to be able to search Book Title, Author & Publisher. Can anyone help me? __________________ Link to comment https://forums.phpfreaks.com/topic/162480-search-3-tables/ Share on other sites More sharing options...
ptolomea Posted June 17, 2009 Share Posted June 17, 2009 you need something like on your results page $bookTitle = $_POST['BtName'] then mysql_query("SELECT [fields you want] FROM [table ie BOOKTITLE] WHERE BtName='" . $bookTitle . "'"); Link to comment https://forums.phpfreaks.com/topic/162480-search-3-tables/#findComment-857631 Share on other sites More sharing options...
kagster Posted June 17, 2009 Author Share Posted June 17, 2009 Thank you for your reply. I have tried this but it doesnt work $query = "SELECT * t.BtName, a.AuthorName, p.PubName FROM author AS a INNER JOIN authorship AS i USING (AuthorId) INNER JOIN BookTitle AS t USING (BtId) INNER JOIN publisher AS p USING (PubId) WHERE a.AuthorName LIKE '%".$_POST["AuthorName"]."%' AND p.PubName LIKE '%".$_POST["PubName"]."%' AND t.BtName LIKE '%".$_POST["BtName"]."%'"; Any idea where I am going wrong? Thank you Link to comment https://forums.phpfreaks.com/topic/162480-search-3-tables/#findComment-857637 Share on other sites More sharing options...
Ken2k7 Posted June 17, 2009 Share Posted June 17, 2009 Why doesn't the book have a foreign key to author? ??? Link to comment https://forums.phpfreaks.com/topic/162480-search-3-tables/#findComment-857662 Share on other sites More sharing options...
kagster Posted June 17, 2009 Author Share Posted June 17, 2009 Sorry, what do you mean? :-\ Link to comment https://forums.phpfreaks.com/topic/162480-search-3-tables/#findComment-857670 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.