Thread: Simple Forums
View Single Post
Old 03-13-2005, 02:09 PM   #4 (permalink)
robert_w_ark
Robert
 
Join Date: Mar 2005
Location: Arkansas
Posts: 3
robert_w_ark is on a distinguished road
Send a message via AIM to robert_w_ark Send a message via Yahoo to robert_w_ark
Lightbulb lol

I dont use other scripts because all of my work is original (And I dont like those annoying advertisements at the bottom too). Anyways, I have the database well figured out, so check this out. I am pretty sure its right..hmm

PHP Code:

# Host: localhost
# Database: newsite
# Table: 'forum_categories'

CREATE TABLE `forum_categories` (
  `
idint(11NOT NULL auto_increment,
  `
namevarchar(100NOT NULL default '',
  `
topicsint(11NOT NULL default '0',
  `
descriptiontext NOT NULL,
  
PRIMARY KEY  (`id`)
ENGINE=MyISAM DEFAULT CHARSET=latin1

# Host: localhost
# Database: newsite
# Table: 'forum_posts'

CREATE TABLE `forum_posts` (
  `
idint(11NOT NULL auto_increment,
  `
category_idint(11NOT NULL default '0',
  `
topic_idint(11NOT NULL default '0',
  `
authorvarchar(100NOT NULL default '',
  `
datevarchar(100NOT NULL default '',
  `
titlevarchar(100NOT NULL default '',
  `
messagetext NOT NULL,
  
PRIMARY KEY  (`id`)
ENGINE=MyISAM DEFAULT CHARSET=latin1

# Host: localhost
# Database: newsite
# Table: 'forum_topics'

CREATE TABLE `forum_topics` (
  `
idint(11NOT NULL auto_increment,
  `
category_idint(11NOT NULL default '0',
  `
titlevarchar(100NOT NULL default '',
  `
authorvarchar(100NOT NULL default '',
  `
postsint(11NOT NULL default '0',
  
PRIMARY KEY  (`id`)
ENGINE=MyISAM DEFAULT CHARSET=latin1
I'm pretty sure thats right.. Anyways the structure (or functions i guess) look likes this:

PHP Code:

<?php
if(preg_match("/forums-included.php/i",$_SERVER['PHP_SELF'])) die(header("Location: /index.php?action=home"));

/* If category_id and topic_id is not set - show categories */
    
if(!isset($_GET['category_id']) && !isset($_GET['topic_id']))
    {
      
$query mysql_query("SELECT * FROM forum_categories ORDER BY name DESC") or die(mysql_error());
      if(
mysql_num_rows($query) == 0)
      {
?>
    <table border="0" cellpadding="0" cellspacing="0" width="94%">
    <tr>
      <td class="contentheader" height="16" colspan="3">
        Error
      </td>
    </tr>
    <tr>
      <td>
        &nbsp;
      </td>
      <td class="contentbox" width="98%">
        There are no categories to choose from yet.&nbsp;&nbsp;<a href="javascript:history.back(-1);">&laquo;&nbsp;Back</a>
      </td>
      <td>
        &nbsp;
      </td>
    </tr>
    </table>
    <br/>
    <br/>
<?php
      
}
      else
      {
        while(
$row mysql_fetch_array($query))
        {
?>
    <table border="0" cellpadding="0" cellspacing="0" width="94%">
    <tr>
      <td class="contentheader" height="16" colspan="3">
        <a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=forums&amp;category_id=<?php echo $row['id']; ?>" class="forums"><?php echo stripslashes($row['name']); ?></a>
      </td>
    </tr>
    <tr>
      <td>
        &nbsp;
      </td>
      <td class="contentbox" width="98%">
        <p align="justify">
          <?php echo stripslashes($row['description']); ?>
        </p>
      </td>
      <td>
        &nbsp;
      </td>
    </tr>
    </table>
    <br/>
    <br/>
<?php
        
}
      }
    }
/* If category_id is set and topic_id is not set - show topics */
    
elseif(isset($_GET['category_id']) && !isset($_GET['topic_id']))
    {
      
$category_id clean($_GET['category_id']);
      
$query mysql_query("SELECT * FROM forum_topics WHERE category_id='".$category_id."'") or die(mysql_error());
      if(
mysql_num_rows($query) == 0)
      {
?>
    <table border="0" cellpadding="0" cellspacing="0" width="94%">
    <tr>
      <td class="contentheader" height="16" colspan="3">
        Error
      </td>
    </tr>
    <tr>
      <td>
        &nbsp;
      </td>
      <td class="contentbox" width="98%">
        There are no topics to choose from in this category.&nbsp;&nbsp;<a href="javascript:history.back(-1);">&laquo;&nbsp;Back</a>
      </td>
      <td>
        &nbsp;
      </td>
    </tr>
    </table>
    <br/>
    <br/>
<?php
      
}
      else
      {
        while(
$row mysql_fetch_array($query))
        {
?>
    <table border="0" cellpadding="0" cellspacing="0" width="94%">
    <tr>
      <td class="contentheader" height="16" colspan="3">
        <a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=forums&amp;category_id=<?php echo $category_id?>&amp;topic_id=<?php echo $row['id']; ?>" class="forums"><?php echo stripslashes($row['title']); ?></a>
      </td>
    </tr>
    <tr>
      <td>
        &nbsp;
      </td>
      <td class="contentbox" width="98%">
<?php
$query2 
mysql_query("SELECT * FROM forum_posts WHERE topic_id='".$row['id']."'") or die(mysql_error());
$total mysql_num_rows($query2);
?>
        Posts: <?php echo $total?>
        <br/>
        Author: <?php echo stripslashes($row['author']); ?>
      </td>
      <td>
        &nbsp;
      </td>
    </tr>
    </table>
    <br/>
    <br/>
<?php
        
}
      }
    }
    else
    {
      
$category_id clean($_GET['category_id']);
      
$topic_id clean($_GET['topic_id']);
      
$query mysql_query("SELECT * FROM forum_categories WHERE id='".$category_id."'") or die(mysql_error());
      if(
mysql_num_rows($query) == 0)
      {
?>
    <table border="0" cellpadding="0" cellspacing="0" width="94%">
    <tr>
      <td class="contentheader" height="16" colspan="3">
        Error
      </td>
    </tr>
    <tr>
      <td>
        &nbsp;
      </td>
      <td class="contentbox" width="98%">
        There are no categories to choose from yet.&nbsp;&nbsp;<a href="javascript:history.back(-1);">&laquo;&nbsp;Back</a>
      </td>
      <td>
        &nbsp;
      </td>
    </tr>
    </table>
    <br/>
    <br/>
<?php
      
}
      else
      {
        
$query mysql_query("SELECT * FROM forum_topics WHERE id='".$topic_id."'") or die(mysql_error());
        if(
mysql_num_rows($query) == 0)
        {
?>
    <table border="0" cellpadding="0" cellspacing="0" width="94%">
    <tr>
      <td class="contentheader" height="16" colspan="3">
        Error
      </td>
    </tr>
    <tr>
      <td>
        &nbsp;
      </td>
      <td class="contentbox" width="98%">
        There are no topics to choose from within this category.&nbsp;&nbsp;<a href="javascript:history.back(-1);">&laquo;&nbsp;Back</a>
      </td>
      <td>
        &nbsp;
      </td>
    </tr>
    </table>
    <br/>
    <br/>
<?php
        
}
/* If category_id and topic_id is set - show posts within that topic */
        
else
        {
          
$query mysql_query("SELECT * FROM forum_posts WHERE category_id='".$category_id."' AND topic_id='".$topic_id."'") or die(mysql_error());
          if(
mysql_num_rows($query) == 0)
          {
?>
    <table border="0" cellpadding="0" cellspacing="0" width="94%">
    <tr>
      <td class="contentheader" height="16" colspan="3">
        Error
      </td>
    </tr>
    <tr>
      <td>
        &nbsp;
      </td>
      <td class="contentbox" width="98%">
        There are no posts in this topic.&nbsp;&nbsp;<a href="javascript:history.back(-1);">&laquo;&nbsp;Back</a>
      </td>
      <td>
        &nbsp;
      </td>
    </tr>
    </table>
    <br/>
    <br/>
<?php
          
}
          else
          {
            while(
$row mysql_fetch_array($query))
            {
?>
    <table border="0" cellpadding="0" cellspacing="0" width="94%">
    <tr>
      <td class="contentheader" height="16" colspan="3">
        <?php echo stripslashes($row['title']); ?>
      </td>
    </tr>
    <tr>
      <td>
        &nbsp;
      </td>
      <td class="contentbox" width="98%">
        <table width="100%" cellspacing="2" cellpadding="0" style="border: 1px solid #CCCCCC;">
        <tr>
          <td align="left" rowspan="2" width="20%">
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
            <tr>
              <td align="left">
                <?php echo stripslashes($row['author']); ?>
              </td>
            </tr>
<?php
$query2 
mysql_query("SELECT * FROM members WHERE username='".$row['author']."'") or die(mysql_error());
$row2 mysql_fetch_array($query2);
if(!empty(
$row['location']))
{
?>
            <tr>
              <td align="left">
                Location: <?php echo stripslashes($row['location']); ?>
              </td>
            </tr>
<?php
}
if(!empty(
$row2['avatar']))
{
?>
            <tr>
              <td align="left">
                <img src="<?php echo stripslashes($row2['avatar']); ?>" border="0" width="150" height="150" alt="Avatar for <?php echo stripslashes($row['author']); ?>
              </td>
            </tr>
<?php
}
?>
            <tr>
              <td align="left">
<?php
if(!empty($row2['aim']))
{
?>
                <a href="aim:goim?screenname=<?php echo stripslashes($row2['aim']); ?>"><img src="aim.gif" onmouseover="this.src='aim-hover.gif';" onmouseout="this.src='aim.gif';" alt="Message <?php echo stripslashes($row2['username']); ?>"></a><br/>
<?php
}
if(!empty(
$row2['msn']))
{
?>
                <a href="javascript:alert('MSN Messenger Handle: <?php echo stripslashes($row2['msn']); ?>');"><img src="msn.gif" onmouseover="this.src='msn-hover.gif';" onmouseout="this.src='msn.gif';" alt="Message <?php echo stripslashes($row2['username']); ?>"></a><br/>
<?php
}
if(!empty(
$row2['yim']))
{
?>
                <a href="ymsgr:sendIM?<?php echo stripslashes($row2['aim']); ?>"><img src="yim.gif" onmouseover="this.src='yim-hover.gif';" onmouseout="this.src='yim.gif';" alt="Message <?php echo stripslashes($row2['username']); ?>"></a><br/>
<?php
}
?>
              </td>
            </tr>
            <tr>
              <td align="left">
                Posts: <?php echo $row2['posts']; ?>
              </td>
            </tr>
            </table>
          </td>
          <td align="center" width="80%">
            <?php echo ucwords(stripslashes($row['title'])); ?>
          </td>
        </tr>
        <tr>
          <td align="left" width="100%">
            <p align="justify">
              <?php echo stripslashes($row['message']); ?>
            </p>
          </td>
        </tr>
        </table>
      </td>
      <td>
        &nbsp;
      </td>
    </tr>
    </table>
    <br/>
    <br/>
<?php
            
}
          }
        }
      }
    }
?>
It works so far except for I havent coded the part to add topics or post posts, lol.. But I think this is right so far.. (This is a file included into index.php fyi..) anyways, if you find any errors (or somewhat of an error) let me know. Peace, -Rob
robert_w_ark is offline   Reply With Quote