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
  • allGenres()
  • saveGenreToBook()
  • clearAllBookGenres()
  • allGenresForBook()
  • distinctGenres()
  1. Week 9: Joins and Better Searching
  2. Creating a Browse by Genre

Building our Queries: Part 1

All of the methods below will go into the bookstore.common.books class

allGenres()

This function will return all the genres in our genres table. By now you should have all the knowledge you need to create this query. If you need to go back and look at the other queries we've developed, go for it.

saveGenreToBook()

This will accept two arguments (data passed into the function) which are the id of a genre and the isbn13 of a book and then insert that data into the genresToBooks table. By now you should have all the knowledge you need to create this query. If you need to go back and look at the other queries we've developed, go for it.

clearAllBookGenres()

This will accept the isbn13 of a book and then delete the records in the genresToBooks table for that isbn13. This is the first query we've written that involves delete but it is not very different from the other queries that we've written. It is VERY important that you include your WHERE clauses in a delete function. Otherwise you can delete all the records in your database.

delete from genresToBooks where isbn13=''

allGenresForBook()

This query is a little more complicated and it will be easier to visualize if we already have data in our table so we will revisit it later. For now simply create the function and have it accept and genreId with the default value of 0 and an isbn with the default value of an empty string

function allGenresForBook(genreId=0, isbn13=''){ }

distinctGenres()

The genrenav.bxm currently has a hardcoded list of genres in it. We want a list of each genre for which there is a book in the database. For example, if there is a genre for “Underwater Basket Weaving” but we have no books on that topic, we do not want to list the genre in our genre nav. What would be the point? Conversely, if we have 50 books on any topic, we don’t want that genre to show up 50 times. We want each genre with a book to be displayed once. To do that we are going to use the “DISTINCT” key word.

function distinctGenres(){ return queryExecute("select distinct g.id, g.name from genrestobooks gtb inner join genres g on g.id = gtb.genreid order by g.name"); }

PreviousAdapting Our DatabaseNextAssigning Genres to a Book in our AddEdit.bxm page

Last updated 1 month ago