I have the following chunk of code to do one of several things, the most important being to set up the main loop from which we will grab db contents (depending on conditions).
These conditions are: whether or not we are looking at a category - whether or not we are looking at an ID - whether or not we are looking at neither (the front page) - whether or not the admin password/username combination is used (for deleting/editing purposes).
$replies is grabbing (if we're looking at an ID) all entries that have a PARENT of the ID being called. $quickinfo is used for setting things like meta tags (title, keywords, etc.)
My only (current) question being: is this efficient? If not, why not.
$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");
}