Web Analytics Made Easy -
StatCounter Cannot display results from a search - CodingForum

Announcement

Collapse
No announcement yet.

Cannot display results from a search

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot display results from a search

    hi I am really stuck on this. Ive been trying to display the results from this search for 2 weeks no and Im getting no joy. please help me. Ive to get this working before Monday
    I want it to display: course code, course year, subject, sitting, year and the link even though the drop downs are only for the 1st three. is this possible?
    The following is the information that I am using, tables and code,
    The database is exampapers,

    the tables are:

    elements

    course_code course_year subject sitting year link
    DT205 2 Calculus/Analysis Semester 2 2006/2007 Click here
    DT205 3 Classical Mechanics Semester 1 2006/2007 Click here
    DT205 3 Classical Mechanics Semester 1 2007/2008 Click here
    DT205 4 Integral Equations Semester 2 2006/2007 Click here
    DT205 4 Differential Equations Semester 1 2006/2007 Click here
    DT205 4 Differential Equations Semester 1 2007/2008 Click here
    DT205 1 Computer Architecture Semester 1 2008/2009 Click here


    coursecodetable

    courseid course_code
    1 dt205
    2 dt008



    courseyeartable

    yearid courseid course_year
    1 1 1
    2 1 2
    3 1 3
    4 1 4
    5 2 1
    6 2 2
    7 2 3




    <?php

    $programme = $progyear = $subjectname = $examyear = null; //declare vars

    $conn= mysql_connect("localhost", "root", "pwd");
    $db = mysql_select_db('exampapers',$conn);

    if(isset($_GET["programme"]) && is_numeric($_GET["programme"]))
    {
    $programme = $_GET["programme"];
    }

    if(isset($_GET["progyear"]) && is_numeric($_GET["progyear"]))
    {
    $progyear = $_GET["progyear"];
    }

    if(isset($_GET["subjectname"]) && is_numeric($_GET["subjectname"]))
    {
    $subjectname = $_GET["subjectname"];
    }

    if(isset($_GET["examyear"]) && is_numeric($_GET["examyear"]))
    {
    $examyear = $_GET["examyear"];
    }

    ?>

    <script language="JavaScript">

    function autoSubmit()
    {
    var formObject = document.forms['theForm'];
    formObject.submit();
    }

    </script>

    <form name="theForm" method="get">



    <select name="programme" onChange="autoSubmit();">
    <option value="null"></option>
    <option value="1" <?php if($programme == 1) echo " selected"; ?>>DT205</option>
    <option value="2" <?php if($programme == 2) echo " selected"; ?>>DT008</option>
    </select>

    <br><br>



    <?php

    if($programme != null && is_numeric($programme))
    {

    ?>

    <select name="progyear" onChange="autoSubmit();">
    <option value="null"></option>

    <?php

    //POPULATE DROP DOWN MENU WITH course_year FROM A GIVEN course_code

    $sql = "SELECT DISTINCT yearid, course_year FROM courseyeartable WHERE courseid = $programme";
    $progyears = mysql_query($sql, $conn);

    while($row = mysql_fetch_array($progyears))
    {
    echo ("<option value=\"$row[yearid]\" " . ($progyear == $row["yearid"] ? " selected" : "") . ">$row[course_year]</option>");
    }

    ?>

    </select>

    <?php

    }

    ?>

    <br><br>

    <?php

    if($progyear != null && is_numeric($progyear) && $programme != null)
    {

    ?>

    <select name="subjectname" onChange="autoSubmit();">
    <option value="null"></option>

    <?php

    //POPULATE DROP DOWN MENU WITH subjects FROM A GIVEN course_code, course_year

    $sql = "SELECT DISTINCT subject from elements WHERE course_year = $progyear ";
    $subjects = mysql_query($sql,$conn);

    while($row = mysql_fetch_array($subjects))
    {
    echo ("<option value=\"$row[subject]\" " . ($subjects == $row["subject"] ? " selected" : "") . ">$row[subject]</option>");
    }

    ?>

    </select>

    <?php

    }

    ?>


    </form>
    Last edited by misticles; Apr 15, 2009, 11:09 PM.

  • #2
    This sure looks like homework to me, and we don't do students' homework.

    If you're in a PHP programming class to learn PHP, you should use Google to
    find the answers, or ask a classmate for help. We can answer specific questions,
    but to write code for you is not going to help you learn.

    Do you even have your web page (and program) online so we can see how it works?
    It would be nice to see the form and what displays when we run it.

    Comment

    Working...
    X