好的,所以我尝试使用此线程上列出的解决方案,并且我得到了一些工作,但不是全部。我正在尝试显示不同的结果,然后按返回结果的数量排序。Soo 如果一个 ID 有 4 个调查的结果,它会显示 4。显然我可以这样做myql_num_rows
但是,我不知道如何按该数量排序,所以它将显示为... 4 3 2 1 而不是.. 2 4 1 3
这是我到目前为止所拥有的,我认为我的 Select 语句是正确的,我只需要正确地回显它。
<?php
$query_db = ("SELECT DISTINCT SGSID FROM SGresult WHERE SGFACemail = '$email'");
$result = mysql_query($query_db, $surveys) or die(mysql_error());
$i = 0;
while ($row = mysql_fetch_assoc($result)) {
$SGSID = $row['SGSID'];
//INSERTED MODIFIED SELECT STATEMENT HERE
$query_check = ("SELECT SGpID, count(*) AS numCount FROM SGresult WHERE SGFACemail = '$email' AND SGSID = '$SGSID' GROUP BY SGpID");
$result_c = mysql_query($query_check, $surveys) or die(mysql_error());
$row2 = mysql_fetch_array($result_c);
$SGpID = $row2[3];
echo $row2['numCount'];
//tried num_rows statement to return value of numCount
//$num_rows2 = mysql_num_rows($result_c, $row2['numCount']);
$num_rows = mysql_num_rows($result_c);
$query_name = ("SELECT * FROM SGsurveyID WHERE SGSID = '$SGSID'");
$result_F = mysql_query($query_name, $surveys) or die(mysql_error($surveys));
$name_row = mysql_fetch_row($result_F);
<?php echo $row2['numCount']; //this returns results, but not the amount of rows
$i++;?>
<tr>
<td><?php echo $i;?></td>
<td><?php echo $name_row[1];?></td>
<td><?php echo $num_rows; ?></td>
<td> <?php echo $row2['numCount']; ?></td>
</tr>
<?php
}
因此,回顾一下,我基本上是尝试对 DISTINCT 结果中返回的行数进行 GROUP BY AND ORDER BY 。
再次感谢您的帮助和指点。请原谅凌乱的代码。