INFO 2480-61: Website Database Implementation
  • Syllabus
  • Welcome Letter
  • Week 1: Software and Setup
    • Folder Structure
    • Git: Getting Started
      • Installing a Git Client
      • Creating a Local Repository
      • Making Changes and Merging them
      • Git Wrap Up
    • Git: Github
      • Creating a New Account
      • Creating a Repo on Github
      • Cloning and Forking
      • Cloning a Repo from Github
      • Pushing Changes to Github.com
      • Github: Adding a Collaborator
    • Command Box
      • Downloading the Software
      • Unzipping and Running the Software for the first time
      • Using CommandBox And Installing the UML-Info package.
      • Setting Up Your Local Server
      • Last Step
    • IDE ( Integrated Development Environment )
      • VS Code
      • IntelliJ
    • Journal
  • Week 2: Review of HTML and CSS
    • Making Point In Time and Working Branches
    • Opening our Project from Week 1 and Starting our BoxLang server
    • HTTP Calls and Requests
    • Making a Static Website Dynamic
    • Creating The Management Index.bxm
    • Creating An HTML Form with Bootstrap
    • Last Steps
  • Week 3: Working Forms and our First Table
    • Data Types
    • Case Types and Naming Conventions
    • Database Tools and Your First DB
      • Installing MySql WorkBench
      • Connecting to your MySQL database
      • Creating Your First Table
    • Working Forms
      • Separation of Concerns
      • Configuring Our Site To Use Our Database
      • Capturing Your Form Data
      • Creating Our Server Side Logic
  • Week 5: SQL and Modelling
    • Our Project And Its Users
    • Introduction to SQL
    • Completing our Articles page.
      • Adapting manageArticles.bxm to display existing articles in the database
      • Completing ManageArticles.bxm to Edit Existing Articles.
      • Making Active Articles Appear On The Public Page
  • Week 6: Managing Books
    • Introduction To Modelling
    • Our Data Models
    • Adapting Our Management Page To Be Multi-Tool
    • Creating The Manage Books Page
    • Adding Search To Our Front Index Page
  • Week 7: Working with Selects, Files, WYSIWYG and more.
    • Adding WYSIWYG Capabilities
    • Adding WYSIWYG to the Manage Books Tool
    • Adding Images To Our Store
    • Creating Our Publisher Select Control
  • Week 9: Joins and Better Searching
    • Displaying Our Publisher
    • Searching By Publisher
    • Creating a Browse by Genre
      • Adapting Our Database
      • Building our Queries: Part 1
      • Assigning Genres to a Book in our AddEdit.bxm page
      • Building our Queries: Part 2
      • Building the GenreNav.bxm
      • Adapting The Details.bxm Page to Search By Genre
  • End of Project Checkllist
Powered by GitBook
On this page
  1. Week 9: Joins and Better Searching

Displaying Our Publisher

PreviousWeek 9: Joins and Better SearchingNextSearching By Publisher

Last updated 2 months ago

In previous exercises, we added a select control to our Manage Books page (addEdit.bxm). However, we haven't completed the process of displaying the publisher on the search resutls page on the front of our website (details.bxm).

The details.bxm template is populated by a query from bookstore.common.books in the searchBooks() function. Currently, that query is returning everything from out books table including the publisherId. We can add that to our display but all we are going to see is the actual Id of the publisher like this:

<bx:output> 
    <image src="/bookstore/common/images/#bookinfo.image[1]#" style="width:300px;float:left; margin:15px"/>
    <div>Title: #bookinfo.title[1]#</div> 
    <div>ISBN-13: #bookinfo.ISBN13[1]#</div> 
    <div>Year: #bookinfo.year[1]#</div> 
    <div>Weight: #bookinfo.weight[1]#</div>
    <div>Publisher: #bookinfo.publisherId[1]#</div>
    <div>Description: #bookinfo.description[1]#</div> 
</bx:output>

That doesn't help us very much since no-one know what publisher "1" is. What we want to do is display the information in the Publishers table which corresponds with the publisherId in the books table. We do this by adding a join to our query. The query which populates our details.bxm page is in the class bookstore.common.books in the searchBooks method. Currently, our query looks like this:

select * from books 
    where title like '%#arguments.searchTerm#%' 
    or isbn13='#arguments.searchTerm#'

We add a join to our query like this:

select * from books 
    inner join publishers on books.publisherId = publisher.id
    where title like '%#arguments.searchTerm#%' 
    or isbn13='#arguments.searchTerm#'

Notice how we add the line inner join publishers on books.publisherId = publisher.id . This tells the SQL server to give us all the row in the books table and the row in the publishers table where the id in the publisher table is the same as the publisherId in the row in the books table. Make sense?

There are several different types of joins but we are going to focus on two: Inner Join and Left Outer Join

  • An inner join returns all the records in both table where there is a match and ONLY if there is a match. If nothing matches, no rows are returned.

  • The left outer join will return all the rows in the first table ( books in our case ) regardless if there is a match or not. If there is a match in the second table ( publishers ) it will return those fields as well.

In your bookstores, adapt your queries and then edit your details.bxm page to display the name of the publisher ( not the id ).

The rendered code in oneresults.bxm