Jump to content

MySQL Library query design


weebulgirl

Recommended Posts

Hi all, hopefully the subject is not extremely vague.

I am trying to code a php/mysql page as a library sort of application.

Database design is:

table library

id | title | author | isbn | copies | owner

 

table libstatus

record | id | borrower | checkout | checkin

 

The id in table library is auto_increment and is used in the id column for libstatus.  Record in libstatus is also auto_increment, primary key.

 

So, I know I could do something like:

foreach (allbooks as book)

{

if (count(select record from libstatus where id = book) > (select copies from library where id=book))

echo "book is not available";

}

 

(sorry for the bad psuedocode)

But I would really like to do some sort of a query that returns all books that are currently checked out, without having to cycle through.  It's been a while since I've worked with SQL..  anybody know what to do?

 

Link to comment
Share on other sites

I would probably store each copy of a book as a separate row.  I would probably do the schema something like this:

 

 

CREATE TABLE books_info (

    isbn int NOT NULL AUTO_INCREMENTING PRIMARY KEY,

    title varchar(255),

    author_id int,

    description text

);

 

(author_id could be mapped to another table called author_groups or something which would contain author groups [obviously] since some books have multiple authors)

 

 

Then I would possibly have a books table where each physical book would have an entry.

 

 

And then, I would use book_id from the books table in books_status.

 

 

 

 

Could be a better way though.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.