Results 1 to 2 of 2

Thread: How to get database report from MySQL or php?

  1. #1
    Join Date
    Feb 2011
    Posts
    1

    Smile How to get database report from MySQL or php?

    Hi,

    Is it possible to generate the following report using SQL or php? Any sample programs or instructions are greatly appreciated.

    Suppose there is a database with 2 tables, Student and Course, with a many-to-many relationship. The report:

    [Firstname] [Lastname] has taken the following course:
    [course title 1]
    [course title 2]
    ……

    [Firstname] [Lastname] has taken the following course:
    [course title 1]
    [course title 2]
    ……

    In particular, I want to have the text “has taken the following course:” in the output.

    Many thanks,
    Libo

  2. #2
    Join Date
    Apr 2011
    Location
    /ramdisk/
    Posts
    6
    Code:
    SELECT 
    
    CONCAT('<html><body><div>', Student.LastName ,',', Student.FirstName, GROUP_CONCAT('<p>',Course.course'</p>'), '</div></body></html>') as report
    
    FROM Student
    INNER JOIN Course
      ON Student.Course_Taken = Course.... wtf- you need another table for an n->m
    
    GROUP BY Student.Student_ID
    
    ORDER BY Student.LastName ASC

    You need another table to show an n->m relationship, so that's the best you'll get: but I'm glad you at least know it's a many to many relationship ;p

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •