Php 允许重复的“标题”值?是否有一个特定的“中点”值,希望得到结果?这就是$submission的值吗?@rdlowery中点是$submission等于标题的位置。它们都是文本。+1如果多个提交记录在点上共享相同的值,那么这里有一些微妙之处。可能有两种情况:
Php 允许重复的“标题”值?是否有一个特定的“中点”值,希望得到结果?这就是$submission的值吗?@rdlowery中点是$submission等于标题的位置。它们都是文本。+1如果多个提交记录在点上共享相同的值,那么这里有一些微妙之处。可能有两种情况:,php,sql,pagination,Php,Sql,Pagination,允许重复的“标题”值?是否有一个特定的“中点”值,希望得到结果?这就是$submission的值吗?@rdlowery中点是$submission等于标题的位置。它们都是文本。+1如果多个提交记录在点上共享相同的值,那么这里有一些微妙之处。可能有两种情况:(没有公认的答案,但更好的搜索标题)。你能更具体一点吗?谢谢。@John,关于哪一部分更具体一点?@pilcrow我怎么能把所有这些合并到一个查询中呢?我试过了,但没有成功。我是不是应该让这个问题保持不变?是的,这就是我的想法。什么不适合你?我
允许重复的“标题”值?是否有一个特定的“中点”值,希望得到结果?这就是$submission的值吗?@rdlowery中点是$submission等于标题的位置。它们都是文本。+1如果多个
提交
记录在点
上共享相同的值,那么这里有一些微妙之处。可能有两种情况:(没有公认的答案,但更好的搜索标题)。你能更具体一点吗?谢谢。@John,关于哪一部分更具体一点?@pilcrow我怎么能把所有这些合并到一个查询中呢?我试过了,但没有成功。我是不是应该让这个问题保持不变?是的,这就是我的想法。什么不适合你?我忘记了数组拼接上的分号($priorEntries,5);然而,我现在已经编辑了我的答案。
$sqlStr = "SELECT title, points, submissionid
FROM submission
ORDER BY points DESC";
$result = mysql_query($sqlStr);
$arr = array();
$count=1;
echo "<table class=\"samplesrec\">";
while ($row = mysql_fetch_array($result)) {
echo '<tr >';
echo '<td>'.$count++.'.</td>';
echo '<td class="sitename1">'.$row["title"].'</td>';
echo '<td class="sitename2"><div class="pointlink2">'.number_format($row["points"]).'</div></td>';
echo '</tr>';
}
echo "</table>";
(
SELECT title, points, submissionid
FROM submission
WHERE points < (SELECT points FROM submission WHERE title = <row_title> LIMIT 1)
ORDER BY points DESC LIMIT 5
)UNION(
SELECT title, points, submissionid
FROM submission
WHERE points > (SELECT points FROM submission WHERE title = <row_title> LIMIT 1)
ORDER BY points ASC LIMIT 5
) ORDER BY points DESC
$entryFound = false;
$counter = 0;
$priorEntries = array();
while ($row = mysql_fetch_array($result)) {
$rowHtml = '<tr >';
$rowHtml .= '<td>'.$count++.'.</td>';
$rowHtml .= '<td class="sitename1">'.$row["title"].'</td>';
$rowHtml .= '<td class="sitename2"><div class="pointlink2">'.number_format($row["points"]).'</div></td>';
$rowHtml .= '</tr>';
if ($entryFound) {
if ($counter < 5) {
$counter++;
echo $rowHtml;
}
} else {
array_unshift($priorEntries, $rowHtml);
if (strcmp($row["title"], $submission) == 0) {
echo implode(array_reverse($priorEntries));
$entryFound = true;
}
array_splice($priorEntries, 5);
}
}
points | title | submissionid
------ + ----- + ------------
...
50 | 'foo' | ABCD01234 <-- If (50, 'foo') is the "midpoint" record,
50 | 'bar' | EF7654321 <-- does (50, 'bar') come before or after?
...
-- First, initialize user variables with the points and
-- title of our midpoint (including midpoint)
--
SELECT @title := title,
@points := points
FROM submission
WHERE title = ? -- bind your $submission variable bere
LIMIT 1;
-- Now, select six records greater than or equal to our
-- midpoint.
--
SELECT title, points, submissionid
FROM ( SELECT title, points, submissionid
FROM submission
WHERE (points, title) >= (@points, @title)
ORDER BY points ASC, title ASC
LIMIT 6) gte
-- and UNION those records with five records less than
-- our midpoint
--
UNION
SELECT title, points, submissionid
FROM ( SELECT title, points, submissionid
FROM submission
WHERE (points, title) < (@points, @title)
ORDER BY points DESC, title DESC
LIMIT 5) lt
-- Finally sort the result set
--
ORDER BY points DESC, title DESC
SELECT
title, points, submissionid
FROM
submission
WHERE
ROWID >= (SELECT ROWID FROM submission WHERE ..... ORDER BY points DESC) - 5
AND
ROWID <= (SELECT ROWID FROM submission WHERE ..... ORDER BY points DESC) + 5
ORDER BY
points DESC
$sqlStr = "SELECT title, points, submissionid FROM submission ORDER BY points DESC";
$result = mysql_query($sqlStr);
$count = 1;
$found = false;
$continue = true;
$records = array();
$row = mysql_fetch_array($result);
while ($row !== false && $continue === true)
{
if($found == false && $row['title'] == $submission)
{
$found = true;
}
elseif($found == true && $count < 6)
{
$count++;
}
elseif($found == true && $count >= 6)
{
$continue = false;
}
$records[] = $row;
$row = mysql_fetch_array($result);
}
if($found === true)
{
if(array_count($records) > 11)
$records = array_splice($records, -11);
}
else
{
$records = array();
}
echo "<table class=\"samplesrec\">";
for($i = 1; $i <= count($records); $i++)
{
echo '<tr >';
echo '<td>'.$i.'.</td>';
echo '<td class="sitename1">'.$records[$i]["title"].'</td>';
echo '<td class="sitename2"><div class="pointlink2">'.number_format($records[$i]["points"]).'</div></td>';
echo '</tr>';
}
echo "</table>";
SELECT title, points, submissionid
FROM submission
WHERE points <=
( SELECT points
FROM submission
WHERE points >=
( SELECT points
FROM submission
WHERE title = @row_title
)
ORDER BY points ASC
LIMIT 1 OFFSET 5
)
ORDER BY points DESC
LIMIT 11 OFFSET 0
SELECT b.title, b.points FROM (
SELECT @rank1 := @rank1 + 1 as slno, temp1.* FROM (
SELECT s1.title, s1.points, COUNT(s2.title) rank
FROM submission s1
JOIN submission s2 ON s1.points <= s2.points
GROUP BY s1.title, s1.points
ORDER BY rank, s1.title ASC
) as temp1
JOIN( SELECT @rank1 := 0 ) AS init
ORDER BY slno
) a
LEFT JOIN (
SELECT @rank2 := @rank2 + 1 as slno, temp1.* FROM (
SELECT s1.title, s1.points, COUNT(s2.title) rank
FROM submission s1
JOIN submission s2 ON s1.points <= s2.points
GROUP BY s1.title, s1.points
ORDER BY rank, s1.title ASC
) as temp1
JOIN( SELECT @rank2 := 0 ) AS init
ORDER BY slno
) b ON a.slno BETWEEN b.slno - 5 AND b.slno + 5
WHERE a.title = <row_title>;