简体   繁体   English

如何显示具有相同ID但不同行值的行?

[英]How to display rows with same id but different row values?

I'm not sure how to describe it in words so i'll show you: View scores table 我不确定如何用语言来描述它,所以我将向您展示: 查看分数表

I'm trying to display rows that has the same id, and display their values but in different tables. 我正在尝试显示具有相同ID的行,并在不同的表中显示其值。 As seen in the picture, I have to make a table like that for every row that has the same ID. 如图所示,我必须为具有相同ID的每一行创建一个类似的表。 The main purpose of it is to compare their scores from before, when they first took the exams, to what the score they got now from the same set of exams. 其主要目的是将他们第一次参加考试时的分数与以前从同一组考试中获得的分数进行比较。

This is what my database looks like right now. 这就是我的数据库现在的样子。 They have different scoreIDs and other row values but has the same id_applicant for it refers that these scores are of this certain applicant. 它们具有不同的scoreID和其他行值,但具有相同的id_applicant,因为它们表示这些分数属于该特定申请人。 Database Snippet 数据库片段

This is what my code for it looks like. 这就是我的代码的样子。 (id_applicant is the one that they will have the same id) (id_applicant是一个具有相同ID的对象)

<!-- VIEW SCORES -->
        <div style="background-color: #E9E9E9" class="tab-pane" id="ViewScoresTab">
            <div class="list-group">
                <div id="view-scores">
                    <div class="form-group" style="margin-left:20px">
                       <br>
                        <div id="inputhere"></div>
                            <h1><span class="label label-default">View Scores</span></h1>
                            <br><br>
                            <table>
                               <tr>
                                  <th bgcolor= '#00BFFF'>TEST</th>
                                  <th bgcolor= '#FFD700'>SCORES</th>
                                  <th bgcolor= '00FF00'>REMARKS</th>
                               </tr>
                       <?php
                            $servername = "localhost";
                            $username = "root";
                            $password = "";
                            $dbname = "offsourcing";

                            $conn = mysqli_connect($servername, $username, $password, $dbname);
                            // Check connection
                            if (!$conn) {
                                die("Connection failed: " . mysqli_connect_error());
                            } 
                            if(isset($ids_holder)){
                            $q = "SELECT * FROM scores WHERE id_applicant = $ids_holder";
                            $result = mysqli_query($conn, $q);
                            $rowcount = mysqli_num_rows($result);
                            for(int x=0;x!=rowcount;x++){
                              //some code for here
                            }

                                 while($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
                                    echo
                               "<tr>
                                  <td class= 'test'> Grammar </td>
                                  <td> $row[2]  </td>
                                  <td> $row[8] </td>
                               </tr>

                               <tr>
                                  <td class= 'test'> Customer Service </td>
                                  <td> $row[3] </td>
                                  <td> $row[9] </td>

                               <tr>
                                  <td class= 'test'> Logical Reasoning </td>
                                  <td> $row[4] </td>
                                  <td> $row[10] </td>
                               </tr>

                               <tr>
                                  <td class= 'test'> Idioms </td>
                                  <td> $row[5] </td>
                                  <td> $row[11] </td>
                               </tr>

                               <tr>
                                  <td class= 'test'> Call Listening (1) </td>
                                  <td> $row[6] </td>
                                  <td> $row[12] </td>
                               </tr>

                               <tr>
                                  <td class= 'test'> Call Listening (2) </td>
                                  <td> $row[7] </td>
                                  <td> $row[13] </td>
                               </tr>"; 
                               mysqli_close($conn);
                           } 
                       }
                               ?>
                            </table>
                            <br><br>  
                            <br><br>  
                            <br><br>


                        </div>
                    </div>
                </div>
           </div>
        </body>
</html>

I'm not exactly sure how to do it yet so any idea? 我不太确定该怎么做,所以知道吗?

Instead of targeting the number in the Array, directly target the column. 而不是定位数组中的数字,而是直接定位该列。 So replacing your while loop with something like: 因此,将您的while循环替换为:

while($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
                           echo
                           '<tr>
                              <td class= 'test'> Grammar </td>
                              <td>'.$row['GrammarScore'].'</td>
                           </tr>

                           <tr>
                              <td class= 'test'> Customer Service </td>
                              <td>'.$row['CustomerServiceScore'].'</td>
                           </tr>'; //etc }

Is this what you mean? 你是这个意思吗? You said something about comparing the older scores to the newer ones, but you didn't really post anything about how you're calling these records, assuming they're on a different table? 您说了一些比较旧分数和新分数的方法,但是您并没有真正发布关于如何调用这些记录的任何信息,前提是它们位于不同的表中?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 选择具有相同id但不同值的不同行 - Selecting different rows with same id but different values 具有相同ID但行名称不同的多行 - Multiple rows with same id but different row names 从2个不同的表中选择值,并在具有相同ID的行中打印值 - Select values from 2 different tables and print values in a row with the same ID 将包含相同ID但数据不同的两行合并为一行 - Merge two rows that contain the same Id but different data into one row 如何计算具有相同值但不同 id 的行 - How to count rows with the same value but different id 如何通过将具有相同id的数据合并为一行来将来自两个不同表的数据显示为一个? - How to display datas from two different tables into one by merging datas with same id into one row? 如何在一行中获取具有相同 id 但在另一列中具有不同值的数据并在 php 中的表中显示一个月 - How to fetch data with same id in a row but different value in another column and display one month into table in php 如何从数据库中选择具有相同id值的多行值并以ajax显示? - How to pick multiple rows of values of the same id value from the database and display in ajax? 如何显示具有相同 ID 的多个值 php - How to display multiple values with same ID php 显示具有相同列值的不同行的多个值 - Display multiple values from different rows with same column value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM