PHP/ Database Challenge HEEEEEllllll:mad:P

Discussion in 'PHP' started by prajita, Oct 30, 2007.

  1. #1
    Hi ,

    I a kinda new to all this database and PHP thing so i would appreciate your help. This forum has been a real help to me in the past.

    I have three tables

    First table named "student"
    stu_id
    f_name
    l_name

    2nd table named "grade"
    stu_id
    cours_num
    grade

    3rd table named "course"
    course_num
    cours_title
    cours_desc

    I have an HTML form with a text field where i need to enter cours_num

    Now when i click submit button it should first look into my database to check if that course number exists or not.

    If it does then it should

    display All the stu_id, f_name and l_name (remember $studentid=$_POST["coursenumber"] and also count the number of record.( relating to that cours_num that we entered from the html page)

    else display message "course number not found";
     
    prajita, Oct 30, 2007 IP
  2. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #2
    so....you want us to write it for you instead of you asking us how ot do it or citing a specific problem?

    if the course exists, you want us to display all student information?

    why is $studentid=$_POST['coursenumber'] ? wouldn't that set the student id equivalent to the course number then, when you actually want to get the student id based off the course number?

    first step is to connect to your db
    mysql_connect($dbtype,$dbusername,$dbpassword); //dbtype usually localhost
    mysql_select_db($db); // select db
    //now you need to check if course is there
    $result=mysql_query("SELECT * from course WHERE course_num='$coursenumber'");
    $rcheck=mysql_num_rows($result) // this will see if your course numb exists
    
    //if it does exist, then you just pull data from grade where 
    //course = $coursenumber and pull data from student where its equal to
    //$stu_id
    //if it doesnt exist then display your error
    if($rcheck==0)
    echo "course number not found";
    elseif ($rscheck!=0)
    {
    $studentid=mysql_query("SELECT stu_id FROM grade WHERE cours_num='$coursenumber'");
    while ($si=$studentid)
    {
    $studentinfo=mysql_query("SELECT * from STUDENT where stu_id='$si'");
    while ($info=$si) {
    //display it however you want
    }
    }
    }
    
    PHP:
    rudimentary, but i think it should work
     
    Lordy, Oct 30, 2007 IP
  3. prajita

    prajita Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    What is $si and $info

    If they are just a variable decleration, how come they are in the while loop?

    Please reply.
     
    prajita, Oct 30, 2007 IP
  4. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #4
    why not? you can declare variables in the loop
     
    Lordy, Oct 30, 2007 IP
  5. prajita

    prajita Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    that while loop will run until when?....I am sorry but i am not trying to be a nutcase....i am just not understanding...
     
    prajita, Oct 30, 2007 IP
  6. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #6
    it will run until there are no more variables in the array
     
    Lordy, Oct 30, 2007 IP