[英]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.