0

this is just a simple code.My problem here is that I can't get or display subject loads of a teacher.

            $sql = mysql_query("SELECT * FROM teachersubject WHERE teacherID ='$id'");
            while($test = mysql_fetch_array($sql))
            {
                $subjectid=$test['subjectID'];
                $getsubject=mysql_query("SELECT * FROM subject WHERE subjectID='$subjectid'") or die(mysql_error());
                $getthis=mysql_fetch_array($getsubject);
                echo "<option value=".$getthis['subjectID'].">".$test['subjectCode']."</option>";
            }
            mysql_close($conn);
            ?>

This in a form of List/Menu..thanks
Please I really need help... :(

4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by simplypixie
0

A quick debugging technique is to check the contents of variables at various stages using a combination of echo, die() and print_r() functions:

$sql = mysql_query("SELECT * FROM teachersubject WHERE teacherID ='$id'");
while($test = mysql_fetch_array($sql))
{        
    // inspect the contents of returned row
    echo(print_r($test, 1)) . '<br />';

    $subjectid=$test['subjectID'];

    // inspect the contents of subjectID
    echo "subjectID: $subjectid<br />";

    $getsubject=mysql_query("SELECT * FROM subject WHERE subjectID='$subjectid'") or die(mysql_error());

    // inspect the query (you can copy it to phpmyadmin)
    echo "getsubject: $getsubject<br />";

    $getthis=mysql_fetch_array($getsubject);

    // inspect the value of $getthis
    echo('getthis:' . print_r($getthis, 1));  

    // you can stop after the first loop to check the values for first row in your time
    die('----------------');

    echo "<option value=".$getthis['subjectID'].">".$test['subjectCode']."</option>";
}
mysql_close($conn);

This way you it will be easier to spot the errors.

Edited by broj1

0

You need to run your fetch_array through another while loop:

while ($getthis = mysql_fetch_array($getsubject)) {
echo "<option value=".$getthis['subjectID'].">".$test['subjectCode']."</option>";
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.