如何修复从数据库检索到的输出

时间:2019-05-11 04:05:01

标签: php html xampp

我正在为员工制定一个计划,以设定他们半年的目标。我一直很好,直到我必须显示所有目标表单管理员才能预览的部分为止。我正在使用包含表的数据库Xampp:

  

(1)员工(2)Goal_tbl_record(3)Goal_tbl_status

我的问题是我试图显示表工作人员的用户名,目标来自goal_tbl_record。我无法直接从goal_tbl_record检索,因为每个目标都包含staff_id。因此,它将显示三次而不是一次。我决定从goal_tbl_status中检索到一个staff_id以与表staff相匹配,并且只显示一次名称。然而.. 它跳过第一个输出。

enter image description here

echo "<form name='frm_teamview' action='$self' method='get'>\n";

$check = mysqli_query ($dbhandler, "SELECT staff.*, goal_tbl_status.* FROM staff INNER JOIN goal_tbl_status ON staff.staff_id = goal_tbl_status.staff_id  WHERE staff.approval_id = '".$id."' AND goal_tbl_status.status='1' ");

        foreach($check as $s)
        {

            $staff_id = $s['staff_id'];
            $fullname = $s['fullname'];


            //Display fullname
            echo "<h2 > ID : <span style='color: blue'> ".strtoupper($staff_id)." </span></h2>";
            echo "<h2 > NAME : <span style='color: blue'> ".strtoupper($fullname)." </span></h2>";

                    echo '<table id="newspaper-a">';
                        echo" <thead>";
                            echo "<tr>";
                                echo '<th scope="col" width="5%" align="center">NO.</th>';
                                echo '<th scope="col" width="20%" align="left">GOAL</th>';
                                echo '<th scope="col" width="15%" align="left">STRATEGY</th>';
                                echo '<th scope="col" width="15%" align="left">MEASURE</th>';
                                echo '<th scope="col" width="7%" align="center">WEIGHT</th>';
                                echo '<th scope="col" width="7%" align="center">PROGRESS</th>';
                                echo '<th align="center" scope="col" width="20%">ACTION</th>';
                            echo "</tr>";
                      echo "</thead> ";
                     echo "<tbody>";

                    $c = 1;
                    $sql_result = mysqli_query($dbhandler,"SELECT * FROM goal_tbl_record WHERE staff_id='".$staff_id."' AND status = '1' ORDER BY goal_id DESC LIMIT 3")or die(mysqli_error());
                    while($row = mysqli_fetch_array($sql_result))

                    {   

                        echo "<tr>";

                        echo "<td align='center'>";

                        echo " Goal ".$c++;

                        echo "</td>\n";

                        echo "<td align='left'>".stripslashes($row['goal'])."</td>\n";

                        echo "<td align='left'>".stripslashes($row['strategy'])."</td>\n";

                        echo "<td align='left'>".stripslashes($row['measure'])."</td>\n";

                        echo "<td align='center'>".stripslashes($row['weight'])."</td>\n";

                        echo "<td align='center'>".stripslashes($row['progress'])."</td>\n";

                        echo "<td align='center'>".$tocomment =  '<a href = goal_addComment.php?id='.$row['goal_id'].'>Add Comment </a>'." | "
                                                  .$toview = '<a href = goal_viewComment.php?id='.$row['goal_id'].'> View All Comment </a>'."</td>\n";
                    }   

            echo "<br><br>";
        }
           echo '</tbody>';

        echo '</table>';

      echo '</div>';

    echo '</br><b> Note: Only submitted form will be shown </b>';

}
echo "</form>";

输出应显示属于正确用户的目标。 我希望我的解释清楚。我该怎么办?

0 个答案:

没有答案