从数据库中检索所有记录时检索并显示php数组值

时间:2021-04-30 13:26:34

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

我在My profile部分显示用户的完整记录,我正在获取所有行,但问题是在行中我有两个字段作为数组,现在我想要'secondarySubject'和'secondaryGrade'显示是这样的

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

2002-2004 ----------- A Level -------学校名称

                  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 -->



        ';



    }



}

1 个解决方案

#1


0  

It looks like those are inside the while statement. Every time it loops it will include it. Try moving it outside the while statement.

看起来这些都在while语句中。每次循环它都会包含它。尝试将其移到while语句之外。

#1


0  

It looks like those are inside the while statement. Every time it loops it will include it. Try moving it outside the while statement.

看起来这些都在while语句中。每次循环它都会包含它。尝试将其移到while语句之外。