SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Dec 2000
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm completely new at this, and the book I purchased on PHP does not show examples of how to write mysql queries based on relational databases. They only show how to retrieve data from 1 database at a time.

    Can someone give me some example queries. I would greatly appreciate the help. Here are the tables I am working with:

    Database name: du

    tables:

    Student
    ID
    FirstName
    LastName
    College
    Major
    PhoneNumber
    GPA

    Classes
    ID
    Course
    Section
    Credits
    StudentID <---relational to ID in Student table

    This query works in Mysql, but not in php:
    SELECT Classes.Course, Classes.Section,Classes.Credits,Classes.Term,Student.FirstName,Student.LastName,Student.College,Student.Major,Student.PhoneNumber,Student.GPA FROM Classes, Student WHERE Student.ID = Classes.StudentID;



    If you are curios, let me explain what I am doing. I have 2 tables in the database "du". The tables are "Student" and "Classes". I intend to have multiple records in "Classes" for each "Student". I know I should break classes into 2 separate databases, but there are way too many classes I would have to input, so I want to keep it the way it is(even though there will be redundant data). I'm doing this for my organization in College. A study group / reporting database in a sense.

    Thanks a lot.

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What exactly isn't working. The query looks okay.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Member
    Join Date
    Dec 2000
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm getting a parse error on the the query.

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why dont you show the php code, we might see the problem.
    Great Dane
    Gokhan ARLI

  5. #5
    SitePoint Enthusiast Sparklit's Avatar
    Join Date
    Jul 2000
    Location
    Victoria,BC,Canada
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Post your relavent PHP code here so we can help you.

  6. #6
    SitePoint Enthusiast Sparklit's Avatar
    Join Date
    Jul 2000
    Location
    Victoria,BC,Canada
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We think alike ;-)

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT Classes.Course, Classes.Section,Classes.Credits,Classes.Term,Student.FirstName,Student.LastName,Student.College,Student.Major,Student.PhoneNumber,Student.GPA FROM Classes, Student WHERE Student.ID = Classes.StudentID;

    Seems like you probably need some other part of your where clause like
    SELECT Classes.Course, Classes.Section,Classes.Credits,Classes.Term,Student.FirstName,Student.LastName,Student.College,Student.Major,Student.PhoneNumber,Student.GPA FROM Classes, Student WHERE Student.ID = Classes.StudentID AND Student.ID = $studentid;

    where $studentid comes from your php script somehow. But as well agree if you post your code here we will be able to help you a lot easier
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Member
    Join Date
    Dec 2000
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <HTML>
    <HEAD>
    <TITLE> test database </TITLE>
    <HEAD>
    <BODY>
    <P>The Complete List</P>
    <BLOCKQUOTE>
    <TABLE border=1>

    <?php
    $db = @mysql_connect("localhost", "root", "root");
    if (!$db) {
    echo( "<P>Unable to connect to the " .
    "database server at this time.</P>" );
    exit();
    }

    mysql_select_db("du",$db);


    $result = mysql_query("SELECT Classes.Course, Classes.Section,Classes.Credits,Classes.Term,Student.FirstName,Student.LastName,Student.College,Student.Major,Student.PhoneNumber,Student.GPA FROM Classes, Student WHERE Student.ID = Classes.StudentID);


    ?>

    that's as far as I got, still trying to get the query to work. Thank you for helping me.


  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Parse Error the first place I would start is the missing quote at the end of the query
    $result = mysql_query("SELECT Classes.Course, Classes.Section,Classes.Credits,Classes.Term,Student.FirstName,Student.LastName,Student.College,Student.Major,Student.PhoneNumber,Student.GPA FROM Classes, Student WHERE Student.ID = Classes.StudentID");
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

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