How to do a search?

Discussion in 'MySQL' started by john128, Sep 6, 2006.

  1. #1
    I have a table in mysql cauled subjects consiting of "id","subject1","subject2","subject3","subject4","subject5". What i want is to write some php code to search these. eg search for all students doing Maths, English and Physics only.

    How do i do this?
     
    john128, Sep 6, 2006 IP
  2. dealsonweb

    dealsonweb Peon

    Messages:
    277
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    MySQL has search function.
    1. Alter table to fullindex on columns.
    2. use Match Against to do search.

    Search web for more detail.
     
    dealsonweb, Sep 6, 2006 IP
  3. ThomasNederman

    ThomasNederman Peon

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I would say your database design is not optimal. I would create 3 tables. One with students, one with what subjects each student is doing
    (studentID, SubjectID) and one table with SubjectID and Subject.

    Then you can use a very easy SQL syntax, select * from Studens S inner join StudentSubjects SS on S.StudentID = SS.StudentID inner join Subjects SU on SU.SubjectID=SS.Subjectid where Subject in("Math","English","Physics");
     
    ThomasNederman, Sep 18, 2006 IP