Location: PHPKode > projects > BSW_Bulletin > addtopic.php

<?php
include("config.php");
//gather the topics
$get_topics_sql = "SELECT topic_id, topic_title, DATE_FORMAT(topic_create_time,  '%b %e %Y at %r') aS fmt_topic_create_time, topic_owner FROM forum_topics ORDER BY topic_create_time DESC Limit 0,10";
$get_topics_res = mysql_query($get_topics_sql) or die(mysql_error($mysql));
if (mysql_num_rows($get_topics_res) < 1) {
	//there are no topics, so say so
	$display_block = "<table align=\"center\"width=\"300\"><td align=\"center\"><em>No topics exist.</em></td></table>";
} else {
	//create the display string
	$display_block = "
	<table width=\"900\" align=\"center\"cellpadding=\"3\" cellspacing=\"1\" border=\"1\">
	<tr>
	<th class=\"topic\" width=\"85%\">TOPIC TITLE</th>
	<th class=\"topic\" width=\"15%\">Reply of POSTS</th>
	</tr>";

// for($k=1;$k<8;$k++){
	while($topic_info = mysql_fetch_array($get_topics_res)){
		
		$topic_id = $topic_info['topic_id'];
		$topic_title = stripslashes($topic_info['topic_title']);
		$topic_create_time = $topic_info['fmt_topic_create_time'];
		$topic_owner = stripslashes($topic_info['topic_owner']);

		//get number of posts
		$get_num_posts_sql = "SELECT COUNT(post_id) AS post_count FROM forum_posts WHERE topic_id = '".$topic_id."'";
		$get_num_posts_res = mysql_query($get_num_posts_sql) or die(mysql_error($mysql));

		while ($posts_info = mysql_fetch_array($get_num_posts_res)) {
			$num_posts = $posts_info['post_count'];
		}

		//add to display
		$display_block .= "
		<tr>
		<td  width=\"85%\" class=\"nform\"><a href=\"showtopic.php?topic_id=".$topic_id."\"><strong>".$topic_title."</strong></a><br/>
		Created on ".$topic_create_time." by ".$topic_owner."</td>
		<td align=\"center\"class=\"bar\" width=\"15%\">".$num_posts."</td>
		</tr>";
	}
	//free results
	mysql_free_result($get_topics_res);
	mysql_free_result($get_num_posts_res);
      

	//close connection to mysql
	mysql_close($mysql);

	//close up the table
	$display_block .= "</table>";

}

?>

<html>
<head>
<title>BSW Topics</title>
<style type="text/css">
.style1 {
	text-align: center;
}
</style>
<link rel="stylesheet" type="text/css" href="bswstyle.css">
<script language="JavaScript" type="text/javascript" src="wysiwyg.js"></script>
</head>
<body>
<table align="center" width="900"><?php include('header.php');?></table>
<table align="center" width="900"><td width="25%" valign="top"align="right" class="topic"><?php if (isset($_COOKIE["user"]))
  echo "Welcome " . $_COOKIE["user"] . "!<br />";
else
  echo "Welcome guest!<br />";?></td><td width="5%" valign="top"align="left" class="topic"><?php if (isset($_COOKIE["user"])){

		
            echo"<a class=\"bar\"href=\"logout.php\">Logout</a>";}	
			
               else {   			
                      header("Location: topic.php");}?></td><td width="40%" valign="top"align="center" class="topic"><?php $ip = getenv("REMOTE_ADDR") ; 

Echo "Your IP is " . $ip;?></td><td width="30%" class="topic" align="center"><?php include('count.php');?></td></table>
<?php echo $display_block; ?>
<table align="center"width="900">

<td class="topic" width="50%" align="left">
<ul><li><a href="registered.php" target="I1">Registered Users</a></li><li><a href="selentry.php">View more topics</a></li></ul>
<iframe id="I1" name="I1"src="inf.htm" width="100%"></iframe></td>
<td width="50%" valign="middle"align="left" class="topic"><?php echo $privacy; $status=$_COOKIE["user"];if($status<>""){
		
            echo"";}	
			
               else {   			
                      header("Location: topic.php");}?></td>
		

 
<table align="center"width="215">

<td class="bar"><p>Would you like to<a href="#Add_a_Topic"> add a topic?</a></p></td>

</table>
<table align="center">
<td style="width=900px:border:none" class="topic">
<h3><a name="Add_a_Topic">Add a Topic</a></h3>
<form method="post" action="do_addtopic.php">
<tr>
<table align="center">

<input  type="hidden" name="topic_owner" value=<?php echo($_COOKIE["user"]);?> size="40" maxlength="150"><tr>
<td style="width:80px;height:20px" valign="middle" align="right">
Topic Title:</td>
<td style="width:182px;height:20px"><input type="text" name="topic_title" size="40" maxlength="150"></td></tr></table>

<table align="center" style="width: 756px"><tr>
<td>Message:</td></tr>
<td>
<textarea id="post_text" name="topic_text" rows="8" wrap="virtual" style="width: 780px"></textarea>
<script language="JavaScript">
  generate_wysiwyg('topic_text');
</script> </table>
<table style="width:100px"align="center"><td class="bar">
<p><input class="bar"type="submit" name="submit" value="Add Topic"></p>
</form>
</td></table>
<table align="center"width="900"><?php include('footer.php');?></table>
</body>
</html>
Return current item: BSW_Bulletin