Jump to content

Recommended Posts

hey guys... im trying to make it so that i can lock the forum on mywebsite if needed for cleaning up ect....

 

this is what i have done so far...

 

set up a tbale called forum_lock  inside is locked with values 0 for unlocked and 1 for locked...

 

i also have my forum page

 

<?php 			 
//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($pagenum)))
{
$pagenum = 1;
}

//Here we count the number of results
//Edit $data to be your query
$forum=$_GET['forum']; 
$data = mysql_query("Select * from forumtutorial_posts where parentid='0' AND forum = '$forum' ORDER BY important, lastrepliedto") or die(mysql_error());
$rows = mysql_num_rows($data);

//This is the number of results displayed per page
$page_rows = 25;

//This tells us the page number of our last page
$last = ceil($rows/$page_rows);

//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}

//This sets the range to display in our query
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
//This is your query again, the same one... the only difference is we add $max into it

{
?>
<p><A href='index.php?page=mainforums'><img src="http://www.runningprofiles.com/images/homeforum.gif" alt="home" border="0"  /></a><A href='index.php?page=post&forum=<?php echo $forum;  ?>'><img src="http://www.runningprofiles.com/images/new_post.gif" border="0"  /></a></p>
<p>users viewing forum = <?php if ($result = mysql_query("SELECT * FROM useronline")) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_array($result)) {
      $last_active = time() - $row['timestamp'];				
      if ($last_active < 3600) {
        $onlineuser[] = $row['user'];
      }
    }
  }
}

if (isset($onlineuser)) {
  if (count($onlineuser) == 1) {
    echo $onlineuser[0];
  } else {
    for ($i=0;$i<count($onlineuser);$i++) {
      if ($i == count($onlineuser)-1) {
        echo " and " . $onlineuser[$i];
      } else {
        echo "  " . $onlineuser[$i];
      }
    }
  }
}

?>

</p>
<table width="99%" class='forum'>
  <tr>
    <td><table class='maintable'>

<tr class='headline'><td> </td>
  <td> </td>
  <td>Topic</td>
  <td width=15%>Topic Starter</td>
<td width="5%">Replies</td><td width="25%">Last replied time</td></tr>
<?

$getthreads="Select * from forumtutorial_posts where parentid='0' and forum = '$forum' ORDER BY important ASC, lastrepliedto DESC $max";


$getthreads2=mysql_query($getthreads) or die("Could not get threads");

while($getthreads3=mysql_fetch_array($getthreads2))

{

  $getthreads3[title]=strip_tags($getthreads3[title]);

  $getthreads3[author]=strip_tags($getthreads3[author]);
  $getthreads3[important]=strip_tags($getthreads3[important]);
      $important=$getthreads3['important'];
?>
<tr <?php if($important==1) {
    $class = "mainrow1";
} else {
    $class = "mainrow";
}  ?> class="<? echo $class?>"><td width="6%" height="39" align="center" valign="middle"><? if($getthreads3[author] == $puser){ ?> <img src="http://www.runningprofiles.com/images/new_posts_icon.gif" alt="My" /> <? }   else { ?> <img src="http://www.runningprofiles.com/images/last_post.gif" alt="My" /> <?} ?>
   <td width="4%" align="center" valign="middle"><?php  if($getthreads3['forumlock'] == 1){echo' <img src="http://www.runningprofiles.com/images/quick_lock.gif" alt="locked"/>';}  if($getthreads3['important'] == 1){echo'<img src="http://www.runningprofiles.com/images/sticky.gif" alt="sticky"/>';} ?></td>
<td width="45%" valign="top"><div align="left"><a href='index.php?page=message&forum=<? echo $forum; ?>&id=<? echo $getthreads3[postid] ?>'><? echo $getthreads3[title] ?></a>  
  
   <?php if($id == 1){ include 'editforum.php';}; ?>
      </div></td>
  <td align="left" valign="middle"><a href='/members/<? echo $getthreads3[author]; ?>'><? echo $getthreads3[author] ?></a></td>
  <td align="center" valign="top"><? echo $getthreads3[numreplies]?></td>
  <td valign="top"><? $dbtime=$getthreads3['lastrepliedto']; $time = date("F j Y, g:i a", $dbtime); echo $time;?><br>
  Last post by <b><? echo $getthreads3[lastposter]?> </b></td></tr>
<?
}
?>
</table></td>
  </tr>
</table>
<br>


</a>
<p>
  <?
echo "<br>";
}
echo "<p>";


// Start links for pages
$maxpage = $totalpages == 0 ? 1 : $totalpages; // add this line
echo "<p align=center>Page $pagenum of $maxpage <br /> "; // change this

// Sets link for previous 25 and return to page 1
    if($pagenum != 1){
        $pageprev = ($pagenum - 1);
         echo "<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=1\"><<</a>  ";
         echo "<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$pageprev\">PREV </a> ";
    }else{
        echo "";
    }

// Loop thru all the pages and echo out the links
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $pagenum){
            echo "[".$i."] ";
        }else{
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$i\">$i</a> ";
        }
    }

// Check for straglers after the limit blocks
    if(($rows % $page_rows) != 0){
        if($i == $pagenum){
            echo "[".$i."] ";
        }else{
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$i\">$i</a> ";
        }
    }
// Print out the Next 25 and Goto Last page links
    if(($rows - ($page_rows * $pagenum)) > 0){
        $pagenext = $pagenum++;
          echo "<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$pagenext\">NEXT </a>  ";
          echo "<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$totalpages\">>></a>  ";
          }
?>
</p>
<p></p>
<table width="14%" border="0" align="left" cellpadding="0" cellspacing="0">
  <tr>
    <td height="33" colspan="2" align="center"><strong>forum key</strong></td>
  </tr>
  <tr>
    <td width="22%" align="center"><img src="http://www.runningprofiles.com/images/quick_lock.gif" alt="locked"/></td>
    <td width="78%">Locked Topic</td>
  </tr>
  <tr>
    <td align="center" valign="middle"><img src="http://www.runningprofiles.com/images/sticky.gif" alt="sticky"/></td>
    <td>Sticky Topic</td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
</table>

 

thing is i tried adding $forum="Select * from forum_lock";

 

 

$forum2=mysql_query($forum) or die("Could not connect to forum");

while($forum3=mysql_fetch_array($forum2))

{

      $forum_lock=$forum3['locked'];
  echo $forum_lock;
  echo 'hey';
if($forum_lock == 1){ echo 'locked'; }  else {

at the top but when i add my end bracket at the bottom then the page displays blank... i think the problem is me not knowing where to add my end brackets... any 1 able to shine the light on how to fit it together

Link to comment
https://forums.phpfreaks.com/topic/113349-locking-up-forum/
Share on other sites

thing is i tried adding $forum="Select * from forum_lock";

 

$forum2=mysql_query($forum) or die("Could not connect to forum");

while($forum3=mysql_fetch_array($forum2))

{

      $forum_lock=$forum3['locked'];
  echo $forum_lock;
  echo 'hey';
if($forum_lock == 1){ echo 'locked'; }  else {

at the top but when i add my end bracket at the bottom then the page displays blank... i think the problem is me not knowing where to add my end brackets... any 1 able to shine the light on how to fit it together

Is that all your code? If it is you cannot leave your else statement open, you'll need to use two closing braces in order for the code to function.

 if($forum_lock == 1){ echo 'locked'; }  else { } // close if/else
} // close while

Link to comment
https://forums.phpfreaks.com/topic/113349-locking-up-forum/#findComment-582435
Share on other sites

well im suppose to put it on the end of the whole code so shows forum if 0 but when i put }} at end of it it does not show any of the page

 

as like here

<td align="center" valign="middle"><img src="http://www.runningprofiles.com/images/sticky.gif" alt="sticky"/></td>
    <td>Sticky Topic</td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
</table>

<?php }} ?> 

Link to comment
https://forums.phpfreaks.com/topic/113349-locking-up-forum/#findComment-582441
Share on other sites

ok i turned error reporting on yet i still get a blank page...

 

here is my code...

 

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 'on');

require_once '../settings.php';
include "connect.php"; //mysql db connection here
$id = $_SESSION['user_id'];  
$puser = get_username($id);

$timestamp = time();
$timeout = $timestamp - 180;
$username= get_username($_SESSION['user_id']);
function selfURL() { 
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; 
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); 
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; } 
function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); }
$filename = (selfURL());
//Insert User
$insert = mysql_query("REPLACE INTO `useronline` SET `timestamp`='$timestamp', `ip`='".$_SERVER['REMOTE_ADDR']."', `file`='$filename',`user`='$username',`user_id`='".$_SESSION['user_id']."'") 
or die(mysql_error()); 

?>
<?php 
$forum="Select * from forum_lock";
$forum2 = mysql_query($forum) or die("Could not connect to forum");

while($forum3=mysql_fetch_array($forum2))

{

      $forum_lock=$forum3['locked'];	
if($forum_lock == 1){ echo 'locked'; }  

      else  {		

//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($pagenum)))
{
$pagenum = 1;
}

//Here we count the number of results
//Edit $data to be your query
$forum=$_GET['forum']; 
$data = mysql_query("Select * from forumtutorial_posts where parentid='0' AND forum = '$forum' ORDER BY important, lastrepliedto") or die(mysql_error());
$rows = mysql_num_rows($data);

//This is the number of results displayed per page
$page_rows = 25;

//This tells us the page number of our last page
$last = ceil($rows/$page_rows);

//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}

//This sets the range to display in our query
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
//This is your query again, the same one... the only difference is we add $max into it

{
?>
<p><A href='index.php?page=mainforums'><img src="http://www.runningprofiles.com/images/homeforum.gif" alt="home" border="0"  /></a><A href='index.php?page=post&forum=<?php echo $forum;  ?>'><img src="http://www.runningprofiles.com/images/new_post.gif" border="0"  /></a></p>
<p>users viewing forum = <?php if ($result = mysql_query("SELECT * FROM useronline")) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_array($result)) {
      $last_active = time() - $row['timestamp'];				
      if ($last_active < 3600) {
        $onlineuser[] = $row['user'];
      }
    }
  }
}

if (isset($onlineuser)) {
  if (count($onlineuser) == 1) {
    echo $onlineuser[0];
  } else {
    for ($i=0;$i<count($onlineuser);$i++) {
      if ($i == count($onlineuser)-1) {
        echo " and " . $onlineuser[$i];
      } else {
        echo "  " . $onlineuser[$i];
      }
    }
  }
}

?>

</p>
<table width="99%" class='forum'>
  <tr>
    <td><table class='maintable'>

<tr class='headline'><td> </td>
  <td> </td>
  <td>Topic</td>
  <td width=15%>Topic Starter</td>
<td width="5%">Replies</td><td width="25%">Last replied time</td></tr>
<?

$getthreads="Select * from forumtutorial_posts where parentid='0' and forum = '$forum' ORDER BY important ASC, lastrepliedto DESC $max";


$getthreads2=mysql_query($getthreads) or die("Could not get threads");

while($getthreads3=mysql_fetch_array($getthreads2))

{

  $getthreads3[title]=strip_tags($getthreads3[title]);

  $getthreads3[author]=strip_tags($getthreads3[author]);
  $getthreads3[important]=strip_tags($getthreads3[important]);
      $important=$getthreads3['important'];
?>
<tr <?php if($important==1) {
    $class = "mainrow1";
} else {
    $class = "mainrow";
}  ?> class="<? echo $class?>"><td width="6%" height="39" align="center" valign="middle"><? if($getthreads3[author] == $puser){ ?> <img src="http://www.runningprofiles.com/images/new_posts_icon.gif" alt="My" /> <? }   else { ?> <img src="http://www.runningprofiles.com/images/last_post.gif" alt="My" /> <?} ?>
   <td width="4%" align="center" valign="middle"><?php  if($getthreads3['forumlock'] == 1){echo' <img src="http://www.runningprofiles.com/images/quick_lock.gif" alt="locked"/>';}  if($getthreads3['important'] == 1){echo'<img src="http://www.runningprofiles.com/images/sticky.gif" alt="sticky"/>';} ?></td>
<td width="45%" valign="top"><div align="left"><a href='index.php?page=message&forum=<? echo $forum; ?>&id=<? echo $getthreads3[postid] ?>'><? echo $getthreads3[title] ?></a>  
  
   <?php if($id == 1){ include 'editforum.php';}; ?>
      </div></td>
  <td align="left" valign="middle"><a href='/members/<? echo $getthreads3[author]; ?>'><? echo $getthreads3[author] ?></a></td>
  <td align="center" valign="top"><? echo $getthreads3[numreplies]?></td>
  <td valign="top"><? $dbtime=$getthreads3['lastrepliedto']; $time = date("F j Y, g:i a", $dbtime); echo $time;?><br>
  Last post by <b><? echo $getthreads3[lastposter]?> </b></td></tr>
<?
}
?>
</table></td>
  </tr>
</table>
<br>


</a>
<p>
  <?
echo "<br>";
}
echo "<p>";


// Start links for pages
$maxpage = $totalpages == 0 ? 1 : $totalpages; // add this line
echo "<p align=center>Page $pagenum of $maxpage <br /> "; // change this

// Sets link for previous 25 and return to page 1
    if($pagenum != 1){
        $pageprev = ($pagenum - 1);
         echo "<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=1\"><<</a>  ";
         echo "<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$pageprev\">PREV </a> ";
    }else{
        echo "";
    }

// Loop thru all the pages and echo out the links
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $pagenum){
            echo "[".$i."] ";
        }else{
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$i\">$i</a> ";
        }
    }

// Check for straglers after the limit blocks
    if(($rows % $page_rows) != 0){
        if($i == $pagenum){
            echo "[".$i."] ";
        }else{
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$i\">$i</a> ";
        }
    }
// Print out the Next 25 and Goto Last page links
    if(($rows - ($page_rows * $pagenum)) > 0){
        $pagenext = $pagenum++;
          echo "<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$pagenext\">NEXT </a>  ";
          echo "<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$totalpages\">>></a>  ";
          }
?>
</p>
<p></p>
<table width="14%" border="0" align="left" cellpadding="0" cellspacing="0">
  <tr>
    <td height="33" colspan="2" align="center"><strong>forum key</strong></td>
  </tr>
  <tr>
    <td width="22%" align="center"><img src="http://www.runningprofiles.com/images/quick_lock.gif" alt="locked"/></td>
    <td width="78%">Locked Topic</td>
  </tr>
  <tr>
    <td align="center" valign="middle"><img src="http://www.runningprofiles.com/images/sticky.gif" alt="sticky"/></td>
    <td>Sticky Topic</td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
</table>
<? }} ?>

 

 

the part im looking at starts like this

<?php 
$forum="Select * from forum_lock";
$forum2 = mysql_query($forum) or die("Could not connect to forum");

while($forum3=mysql_fetch_array($forum2))

{

      $forum_lock=$forum3['locked'];	
if($forum_lock == 1){ echo 'locked'; }  

      else  {?> 

 

and finishes right at the bottom of the page with }}

Link to comment
https://forums.phpfreaks.com/topic/113349-locking-up-forum/#findComment-582768
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.