为什么我会返回重复的结果?
Why am I returning duplicate results?
我先说这对我来说是全新的,不管它们是不是高级动作,我只是从其他产品中拼凑出来并适应我的需要。大术语,我不太明白,我知道基础知识,我知道我要实现的目标就是这样哈哈。
所以我已经用这个玩了一段时间了,我已经设法让它工作了,但我现在得到了重复的结果。
这是我的代码:
<?php
$addonid = $db->query_read("
SELECT drc.threadid AS threadid
FROM `" . TABLE_PREFIX . "modsys_settings` AS drc
LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread
ON(drc.mod_addons=" . $threadinfo['threadid'] . ")
WHERE thread.threadid IN (" . $threadinfo['threadid'] . ")
");
while ($addons = $db->fetch_array($addonid)) {
$ci_counter = $db->query_read("
SELECT drc.mod_addons AS addon, drc.threadid, thread.threadid AS threadid, thread.title AS threadtitle
FROM `" . TABLE_PREFIX . "modsys_settings` AS drc
LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread ON(drc.mod_addons=" . $threadinfo['threadid'] . ")
WHERE thread.threadid IN (" . $addons['threadid'] . ")
");
while ($counter = $db->fetch_array($ci_counter)) {
$post['addons'] .= '<li><a href="showthread.php?t=' . $addons['threadid'] . '">' . $counter['threadtitle'] . '</a></li>';
}
}
?>
这到底是什么乱七八糟的东西!?好吧,这就是我设法开始工作的原因,哈哈,那么它有什么作用呢?简单来说,它在一列中查找 threadid
,然后如果它在另一个 table 列中,它会从 table 中获取标题列。然后它使用变量作为值为它们中的每一个创建一个列表link。当它真正起作用时,我感到震惊,这不是我在这里的目的,但可以随意告诉我如何改进它,哈哈。
问题是,它返回所有东西的两倍,所以不是得到
<li><a href="showthread.php?t=4">result</a></li>
<li><a href="showthread.php?t=5">result 2</a></li>
我得到
<li><a href="showthread.php?t=4">result</a></li>
<li><a href="showthread.php?t=4">result</a></li>
<li><a href="showthread.php?t=5">result 2</a></li>
<li><a href="showthread.php?t=5">result 2</a></li>
这是为什么?我能做些什么来解决它?
我已经从循环中删除了查询,但现在它只返回它找到的第一列的重复项(即 4)
<?php
$addonid = $db->query_read("
SELECT drc.threadid AS threadid
FROM `" . TABLE_PREFIX . "modsys_settings` AS drc
LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread
ON(drc.mod_addons=" . $threadinfo['threadid'] . ")
WHERE thread.threadid IN (" . $threadinfo['threadid'] . ")
");
$addons = $db->fetch_array($addonid);
$ci_counter = $db->query_read("
SELECT drc.mod_addons AS addon, drc.threadid, thread.threadid AS threadid, thread.title AS threadtitle
FROM `" . TABLE_PREFIX . "modsys_settings` AS drc
LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread ON(drc.mod_addons=" . $threadinfo['threadid'] . ")
WHERE thread.threadid IN (" . $addons['threadid'] . ")
");
while ($counter = $db->fetch_array($ci_counter)) {
$post['addons'] .= '<li><a href="showthread.php?t=' . $addons['threadid'] . '">' . $counter['threadtitle'] . '</a></li>';
}
?>
返回:
<li><a href="showthread.php?t=4">result</a></li>
<li><a href="showthread.php?t=4">result</a></li>
$addonid = $db->query_read ("
SELECT drc.threadid AS threadid
FROM `" . TABLE_PREFIX . "modsys_settings` AS drc
LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread
ON(drc.mod_addons=" . $threadinfo['threadid'] . ")
WHERE thread.threadid IN (" . $threadinfo['threadid'] . ")
");
while ($addons = $db->fetch_array ($addonid)) {
$ci_counter = $db->query_read ("
SELECT drc.mod_addons AS addon, drc.threadid, thread.threadid AS threadid, thread.title AS threadtitle
FROM `" . TABLE_PREFIX . "modsys_settings` AS drc
LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread ON(drc.mod_addons=" . $threadinfo['threadid'] . ")
WHERE thread.threadid IN (" . $addons['threadid'] . ")
");
$counter = $db->fetch_array ($ci_counter);
if($counter != ''){
$post['addons'] .= '<li><a href="showthread.php?t=' .$addons['threadid'] . '">'. $counter['threadtitle'] .'</a></li>';
}
}
我先说这对我来说是全新的,不管它们是不是高级动作,我只是从其他产品中拼凑出来并适应我的需要。大术语,我不太明白,我知道基础知识,我知道我要实现的目标就是这样哈哈。
所以我已经用这个玩了一段时间了,我已经设法让它工作了,但我现在得到了重复的结果。
这是我的代码:
<?php
$addonid = $db->query_read("
SELECT drc.threadid AS threadid
FROM `" . TABLE_PREFIX . "modsys_settings` AS drc
LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread
ON(drc.mod_addons=" . $threadinfo['threadid'] . ")
WHERE thread.threadid IN (" . $threadinfo['threadid'] . ")
");
while ($addons = $db->fetch_array($addonid)) {
$ci_counter = $db->query_read("
SELECT drc.mod_addons AS addon, drc.threadid, thread.threadid AS threadid, thread.title AS threadtitle
FROM `" . TABLE_PREFIX . "modsys_settings` AS drc
LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread ON(drc.mod_addons=" . $threadinfo['threadid'] . ")
WHERE thread.threadid IN (" . $addons['threadid'] . ")
");
while ($counter = $db->fetch_array($ci_counter)) {
$post['addons'] .= '<li><a href="showthread.php?t=' . $addons['threadid'] . '">' . $counter['threadtitle'] . '</a></li>';
}
}
?>
这到底是什么乱七八糟的东西!?好吧,这就是我设法开始工作的原因,哈哈,那么它有什么作用呢?简单来说,它在一列中查找 threadid
,然后如果它在另一个 table 列中,它会从 table 中获取标题列。然后它使用变量作为值为它们中的每一个创建一个列表link。当它真正起作用时,我感到震惊,这不是我在这里的目的,但可以随意告诉我如何改进它,哈哈。
问题是,它返回所有东西的两倍,所以不是得到
<li><a href="showthread.php?t=4">result</a></li>
<li><a href="showthread.php?t=5">result 2</a></li>
我得到
<li><a href="showthread.php?t=4">result</a></li>
<li><a href="showthread.php?t=4">result</a></li>
<li><a href="showthread.php?t=5">result 2</a></li>
<li><a href="showthread.php?t=5">result 2</a></li>
这是为什么?我能做些什么来解决它?
我已经从循环中删除了查询,但现在它只返回它找到的第一列的重复项(即 4)
<?php
$addonid = $db->query_read("
SELECT drc.threadid AS threadid
FROM `" . TABLE_PREFIX . "modsys_settings` AS drc
LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread
ON(drc.mod_addons=" . $threadinfo['threadid'] . ")
WHERE thread.threadid IN (" . $threadinfo['threadid'] . ")
");
$addons = $db->fetch_array($addonid);
$ci_counter = $db->query_read("
SELECT drc.mod_addons AS addon, drc.threadid, thread.threadid AS threadid, thread.title AS threadtitle
FROM `" . TABLE_PREFIX . "modsys_settings` AS drc
LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread ON(drc.mod_addons=" . $threadinfo['threadid'] . ")
WHERE thread.threadid IN (" . $addons['threadid'] . ")
");
while ($counter = $db->fetch_array($ci_counter)) {
$post['addons'] .= '<li><a href="showthread.php?t=' . $addons['threadid'] . '">' . $counter['threadtitle'] . '</a></li>';
}
?>
返回:
<li><a href="showthread.php?t=4">result</a></li>
<li><a href="showthread.php?t=4">result</a></li>
$addonid = $db->query_read ("
SELECT drc.threadid AS threadid
FROM `" . TABLE_PREFIX . "modsys_settings` AS drc
LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread
ON(drc.mod_addons=" . $threadinfo['threadid'] . ")
WHERE thread.threadid IN (" . $threadinfo['threadid'] . ")
");
while ($addons = $db->fetch_array ($addonid)) {
$ci_counter = $db->query_read ("
SELECT drc.mod_addons AS addon, drc.threadid, thread.threadid AS threadid, thread.title AS threadtitle
FROM `" . TABLE_PREFIX . "modsys_settings` AS drc
LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread ON(drc.mod_addons=" . $threadinfo['threadid'] . ")
WHERE thread.threadid IN (" . $addons['threadid'] . ")
");
$counter = $db->fetch_array ($ci_counter);
if($counter != ''){
$post['addons'] .= '<li><a href="showthread.php?t=' .$addons['threadid'] . '">'. $counter['threadtitle'] .'</a></li>';
}
}