Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > PHP
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 03-12-2005, 07:31 PM   #1 (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
Exclamation Simple Forums

Hey - Robert here. I am wondering if anyone out there would mind helping me code a forums. I dont need nothing fancy or anything else of the sort. However, I do want the forums to all be in just one function. Basically, All that will be on forums is this..
  • Main Page: List of preset categories (from mysql)
  • Within each category, lists the topics posted (limit the last 50 topics posted in, others will be ignored)
  • Once in a topic, show the posts
  • In the posts, show (1) Author of Post (2) Authors Avatar (3) Authors Total Number of Posts (4) Authors Signature (5) The message (6) Subject of Post (7) Date Posted
  • There will be no admin panel. If I need to remove a post, I'll just do it through MySQL


If anyone can help, Please let me know by either email (robertark[at]gmail.com), YIM (robert_w_ark2006), or AIM (robertark2002)

Someone please help, I cant seem to get the structure in my head right. Thanks in advance, -Robert
__________________
robert_w_ark is offline   Reply With Quote
Old 03-12-2005, 10:40 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,398
sde is on a distinguished road
Hi Robert, welcome to the forums.

I can't speak for anyone but myself, but I think you will get a better responses if you ask for help on little chunks.

For example, it seems right now, you need to focus on the datbase structure first. When I'm working on structure, usually I'll do it with pencil and paper first to write down all the tables and fields I need to make. Once it makes sense, then I start creating the database.

Once you create that, then proceed with creating your functions.

There are many ways to do this. I'm curious, why don't you use something that has already been made, like phpBB?

What your asking isn't something that someone can just help you with as a whole unless they wanted to devote a lot of time there with you. Even for an advanced programmer, forums aren't the simplest thing to write.

My advice would be to take it in small bites, .. ask very specific questions here and you are sure to get answers. I am more willing and able to answer a specific question rather than how to do an entire project.
__________________
testing 1 2 3
sde is online now   Reply With Quote
Old 03-13-2005, 08:50 AM   #3 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Exactly, unless you're just wanting to create your own for fun/education, there are plenty of forum/bbs packages out there for use. phpBB and alike are pretty large and complex, but there are many others that are small enough to get familiar with. (without having to be a php expert)

-r
__________________
idx is offline   Reply With Quote
Old 03-13-2005, 01: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
Old 03-13-2005, 03:05 PM   #5 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Well, not all packages have advertisements and clauses where you can't remove them. (eg: ipb)

Looks like you have a good start, but I'm not sure what the `one function` goal is for. You can still have a clean setup where the forums can be included in other portions of the site without much effort. Splitting functionality into separate files will help greatly in the long run.. (..splitting logic from the html via some templating helps too)

-r
__________________
idx is offline   Reply With Quote
Old 03-14-2005, 05:13 PM   #6 (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
Wink woo hoo

As a matter of fact. I did (somehow) get the forums completly coded, and it works like a charm. Way to go me. lol - I knew that it would be a better idea to code my own forums instead of having someone else code them mainly for the fact that I need to learn. Well - In turn, I did. I greatly appreciate all your comments, but I'm afraid I probobly wont need them anymore - Also - Thanks for your encouragement (Even if you didnt show it) - It taught me a lesson (MAKE YOUR OWN FORUMS!) lol - So once again, thanks, -Rob
__________________
robert_w_ark is offline   Reply With Quote
Old 03-14-2005, 05:39 PM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,398
sde is on a distinguished road
i can't tell if you're sincere or sarcastic, but hopefully you are sincere. if you take into consideration my first reply, you will generally get better help when asking very specific questions, rather than a post so open ended.

you asked if anyone would mind helping you .. so should we have said "no, we dont' mind helping you?" .. that is the only question i really saw asked.

anyway, good job, glad to hear your successfull, even though we didn't show any encouragement to all the questions you did not ask.
__________________
testing 1 2 3
sde is online now   Reply With Quote
Old 03-14-2005, 06:07 PM   #8 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Quote:
unless you're just wanting to create your own for fun/education
..figured that was my encouragement part.

If it's for fun or education, do it. There's nothing like writing something from scratch when it works correctly.

Although these days I'm in work mode, so I typically don't have lots of free time to write things for fun.. If I can find something that works that isn't going to be too much of a PITA down the road, then I use it and move on.

I do write a moderate amount of php stuff at work from scratch, but it's the niche stuff that you just aren't going to find out there.

-r
__________________
idx is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
c simple question problem with switch case if13121 Standard C, C++ 1 10-24-2004 09:43 PM
Simple C program Spooky Standard C, C++ 1 10-22-2004 07:26 AM
Can't do a simple flippin' update . . . metazai PHP 10 06-04-2004 11:50 AM
Discussion board of your dreams - Simple Machnies Forums Phoenix PHP 0 08-10-2003 02:59 PM


All times are GMT -8. The time now is 11:44 AM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle