0

我有以下代码块来做几件事之一,最重要的是设置我们将从中获取数据库内容的主循环(取决于条件)。

这些条件是:我们是否正在查看一个类别 - 我们是否正在查看一个 ID - 我们是否都没有查看(首页) - 是否使用管理员密码/用户名组合(用于删除/编辑目的)。

$replies 正在抓取(如果我们正在查看 ID)所有具有被调用 ID 的 PARENT 的条目。$quickinfo 用于设置元标签(标题、关键字等)

我唯一(当前)的问题是:这有效吗?如果没有,为什么不呢。

$selection = "ID,CONTENT,IP,SUBJECT,CATEGORY,APPROVED,DATE,PARENT,
              PASSWORD,USERNAME,THANKS,DISAPPROVE,IPS,BUMPS";

$id = strip_tags($id);
$category = strip_tags($category);
$threads = mysql_query("SELECT COUNT(*) FROM $board") or die();
list($threadsTotal) = mysql_fetch_row($threads);
$threadsTotal_pages = ceil($threadsTotal / $POSTSPERPAGE);
$threadsPage = intval(@$_GET["page"]);

if (0 == $threadsPage)
{
    $threadsPage = 1;
}

$threadsStart = $POSTSPERPAGE * ($threadsPage - 1);
$threadsMax = $POSTSPERPAGE;

if ($category > "" && $id == ""
    && $passw != <ONE MISTAKE HERE> $adminPass 
    && $username != <ANOTHER MISTAKE HERE> $adminID)
{
    $threads = mysql_query("SELECT $selection FROM $board WHERE PARENT=0
                             AND CATEGORY='$category'
                             ORDER BY ID DESC LIMIT $threadsStart, $threadsMax");
}

if ($category == "" && $id == "" &&
    $passw !== <NOT EQAULS DOES NOT REQUIRE TWO EQUAL SIGNS AGAIN>
    $adminPass && $username != <AND AGAIN> $adminID)
 {
     $threads = mysql_query("SELECT $selection FROM $board WHERE PARENT=0
                              ORDER BY ID DESC LIMIT $threadsStart, $threadsMax");
 }

 // PLEASE CHECK THE NOT EQUALS FUTHER ON....

 if ($id > "" && $passw != $adminPass && $username != $adminID)
 {
     $threads = mysql_query("SELECT $selection FROM $board WHERE PARENT=0
                             AND ID=$id LIMIT 1");

     $quickinfo = mysql_query("SELECT COUNT(*) FROM $board") or die();
     $quickinfo = mysql_query("SELECT ID,CONTENT,SUBJECT,CATEGORY,USERNAME FROM
                               $board WHERE PARENT=0 AND ID=$id LIMIT 1");

     $replies = mysql_query("SELECT COUNT(*) FROM $board") or die();
     $replies = mysql_query("SELECT $selection FROM $board WHERE PARENT=$id
                             ORDER BY ID ASC");

     while (list( $ID, $CONTENT, $SUBJECT, $CATEGORY, $USERNAME) =
            mysql_fetch_row($quickinfo))
     {
         $threadID = $ID;
         $threadContent = $CONTENT;
         $threadSubject = $SUBJECT;
         $threadCategory = $CATEGORY;
         if ($USERNAME > "")
         {
             $threadAuthor = $USERNAME;
         }
         elseif ($USERNAME == "")
         {
             $threadAuthor = "Anonymous";
         }
     }

 } // That is the end of your if

 if ($passw == $adminPass && $username == $adminID)
 {
     $threads = mysql_query("SELECT $selection FROM $board ORDER 
                             BY APPROVED DESC LIMIT $threadsStart,
                                                    $threadsMax");
 }
4

2 回答 2

1

Matt- 重新格式化代码,还发现您使用 '!==' 表示 '!-'

此外,您应该考虑使用 mysqli 或 POD。不推荐使用 PHP 的 mysql 库。

于 2012-10-12T23:11:22.267 回答
0

我想我看到了一个问题。我相信你真的想要这个

if ($category > "" && $id == ""
    && $passw != <ONE MISTAKE HERE> $adminPass 
    && $username != <ANOTHER MISTAKE HERE> $adminID)

{

成为这个

if ($category > "" && $id == ""
    && ($passw != <ONE MISTAKE HERE> $adminPass 
    || $username != <ANOTHER MISTAKE HERE> $adminID))

{

或者可能,你可能想要另一个 || 代替另一个&&,我不完全确定类别和ID的逻辑。

否则,您只需在页面上查询一次数据库,这似乎是一个非常有效的设置。

于 2012-10-13T01:02:13.850 回答