【问题标题】:retrieve and display php array values when retrieving all records from database从数据库中检索所有记录时检索并显示 php 数组值
【发布时间】:2014-04-14 21:22:20
【问题描述】:

我在“我的个人资料”部分显示用户的完整记录,我正在获取所有行,但问题在于行内我有两个字段作为数组,它们是“secondarySubject”和“secondaryGrade”现在我希望显示是这样的

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

                  Science          A
                  Maths            B

我可以显示它们,但它会打印每个科目的日期、学校名称和级别名称,而不是只为所有科目打印一次。我正在发布我的代码,有人可以帮助我吗?

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



        ';



    }



}

【问题讨论】:

    标签: php mysql arrays database


    【解决方案1】:

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

    【讨论】:

    • 嗨,循环是获取所有记录,我希望学校名称只显示一次以用于该学校的记录。
    猜你喜欢
    • 2016-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-08
    相关资源
    最近更新 更多