I am displaying the complete record of the user in the My profile section, I am fetching all the rows , but the problem is within the rows I've got two fields as arrays, which are 'secondarySubject' and 'secondaryGrade' now I want the display to be something like this

2002-2004 ----------- A Level ------- School Name

                  Science          A
                  Maths            B

I am able to display them but it prints the dates, school name and level name with every subject rather than just once for all the subjects. I am posting my code, can someone pleaseeee help me with it.

$result2 = $db->query('

    SELECT *

    FROM secondaryEducation

    WHERE userID = "'.$graduateID.'"

    ORDER BY secondaryFinishDate DESC

    ');



    $totalRows2 = mysql_num_rows($result2);

    if($totalRows2 > 0)

    {

        $html .= '<h2>Secondary Education: '.$option.'</h2>';


        while($row = mysql_fetch_assoc($result2))

        {



            $startYear = formatDate($row['secondaryStartDate'], 'Y');

            $finishYear = formatDate($row['secondaryFinishDate'], 'Y');

            if (!empty($row['secondaryGrade']))

                $secondaryGrade = getSecondaryGradeName($row['secondaryGrade']);

            else

                $secondaryGrade = $row['secondaryGradeCustom'];

            $html .= '



                <div class="secondaryListing">

                    <div><strong>'.$startYear.' - '.$finishYear.' '.stripslashes($row['secondarySchool']).'</strong></div>

                    <div>'.stripslashes(getSecondaryLevelName($row['secondaryLevel'])).' in '.stripslashes(getSecondarySubjectName($row['secondarySubject'])).' - '.stripSlashes($secondaryGrade).'</div>

                </div><!-- End education listing -->



            ';



        }



    }
Member Avatar for diafol

am able to display them but it prints the dates, school name and level name with every subject rather than just once for all the subjects. I am posting my code, can someone pleaseeee help me with it.

Take the dates, school name out of the while loop. Print them before the loop.

@diafol

That loop is to print all records, when i take them out it just prints it for one records and not all, please can you help me out with this? How can i have two nested loops? first one to loop through all rows and second one to check if school name is the same?

school = "";
loop (rows) {
    if rows[school] != school {
        print school
        school = rows[school]
    }
    do other stuff
}
commented: Need to show subject and grade grouped by school name, this didn't work :( +0

can you post your database structure.

003c018c5c27b70130e1feb25aedfd1d

This post has no text-based content.
Member Avatar for diafol

This DB is not normalised. You should have related tables.

I'm assuming that the user will only have one school, otherwise it needs to be a little different.

userschool

userschool_id [PK]
user_id [FK]
school_id [FK]
school_startdate
school_finishdate

school

school_id [PK]
schoolname
...

user

user_id [PK]
username
pw
...

qualifications

qual_id [PK]
qualname
quallevel_id [FK]
subject_id [FK]
customgradetype_id - not constrained - uses gradetype_id from qualification_level table if set to NULL/0

qualification_level

quallevel_id [PK]
quallevel
gradetype_id [FK]

gradetypes

gradetype_id [PK]
gradetype (title, e.g. Single GCSE, BTEC Single)
grades (string list)*

  • this could be broken down further again to more tables.

Anyway, something to think about.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.