Can't get query right

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DavidPr
    New Member
    • Mar 2007
    • 155

    Can't get query right

    I have a database table containing the Bible. It has these fields:

    number, book, chapter, verse, text

    where:
    number = the number of the book (1 out of 66, Genesis = 1, etc.)
    book = name of the book (Genesis, Exodus, etc.)
    chapter = self explanatory
    verse = the number of the verse 1, 2, 3, etc.
    text = the verse text

    I've tried without success to fill a table with the books in one column and the chapters of that book in the adjacent column.

    Example:

    Genesis 1, 2, 3, 4, 5, 6, etc.
    Exodus 1, 2, 3, 4, 5, 6, etc.
    and so on and so on.

    Any ideas how I can accomplish this?

    Thanks
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    I don't really get what it is you are trying to do.
    Are you trying to create a database table, who's first column would be a book name, followed by a column for each chapter?
    Like:
    Code:
    +----------+-----+-----+-----+-----+-----+
    | Book     | 1   | 2   | 3   | 4   | etc |
    +----------+-----+-----+-----+-----+-----+
    | Genesis  | txt | txt | txt | txt | txt |
    | Exodus   | txt | txt | txt | txt | txt |
    +----------+-----+-----+-----+-----+-----+
    Or are you trying to print a HTML table?

    Please elaborate.

    Comment

    • DavidPr
      New Member
      • Mar 2007
      • 155

      #3
      Right, I already have the database table and I'm trying to populate an HTML table.

      The way I have it right now is a single html page with all the books of the Bible listed in one column with the chapter numbers hard coded in an adjacent column like I described above. I was looking for a little simpler way of doing this than hard coding it.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Ok.

        Then all you need to do is fetch the name of the book and the max number of chapters for that book. (Assuming they don't all have the same number of chapters?)

        Which could be as simple as:
        [code=sql]SELECT book, MAX(chapter) FROM biblie GROUP BY book[/code]

        Then, you would simply print a header row, where you would have a column for the book, and a second column that has the "colspan" attribute set to highest number of chapters from any of the books.

        Followed by a row for each book, each having the book name in the first column and a single <td> for each chapter.
        Remember to fill in the missing columns tho if the book doesn't have enough chapters to fill the "colspan" you set on the header column.
        Missing columns can mess with the layout of the table.

        Comment

        Working...