0
我希望有人能幫助大家尖叫!聲明中的循環問題
基本上我試圖用下面的語句做一些事情;
首先,我想檢查用戶標識是否存在於member_categories_position中。 如果是我想然後排除第二個語句中的所有條目,其中member_id等於第一條語句的所有結果 第三個語句是else語句,如果member_id不存在於member_categories位置中,則顯示else語句。
問題 - 第一個系統的結果很好,但是當我嘗試插入第二個語句(!='$ memid')時,沒有產生任何結果,也沒有任何效果。我認爲問題是$ memid是一個循環結果。
如何獲得第二個聲明,說member_categories_position中的任何member_id都不會在該聲明中顯示?
$sql2 = "
SELECT *
FROM member_categories_position a
JOIN member_users b
ON b.id = a.member_id";
$rs2 = mysql_query($sql2);
while ($row = mysql_fetch_array($rs2))
{
$memid = "".$row['member_id']."";
}
if(mysql_num_rows($rs2) != 0)
{
$new= "
SELECT *
FROM member_categories
JOIN member_users
ON member_categories.member_id=member_users.id
JOIN member_config
ON member_categories.member_id=member_config.member_id
WHERE
member_categories.categories='$category'
AND member_categories.member_id !='$field'
GROUP BY member_config.member_id
ORDER BY RAND() limit 0,42";
$rs = mysql_query($new);
while ($row = mysql_fetch_assoc($rs))
{
echo "result excluding member ids from the first statement";
}
echo "<div class=\"clear\"></div>";
}
else
{
$new= "
SELECT *
FROM member_categories
JOIN member_users
ON member_categories.member_id=member_users.id
JOIN member_config
ON member_categories.member_id=member_config.member_id
WHERE
member_categories.categories='$category'
GROUP BY member_config.member_id
ORDER BY RAND() limit 0,42";
$rs = mysql_query($new);
while ($row = mysql_fetch_assoc($rs))
{
echo "Result with all member ids";
}
echo "<div class=\"clear\"></div>";
} } <-- (second is a stray from original post)
請編輯您上面的代碼使用正確的縮進 - 它會讓你更容易讓我們來幫助你。 – jball 2010-12-02 16:52:55
$ field和$ category從哪裏得到它們的值? – 2010-12-02 17:07:20