The list of all PHP and Mysql posts

How to show posts inside of a forum

Assume that our forum has five fields : (for example visit : http://story-world.99k.org/)

1.Satire Stories
2.Drama Stories
3.Tragic Stories
4.Jokes
5.other not listed catagories

We want to direct our user to the posts under the clicked field. We can do it just by one common page , but we send a variable to the common page to inform it which field the user requested.
To know how to add variables to a url address see :

http://webprogram4beginners.blogspot.com/2011/02/how-to-add-variable-to-url-adress.html
 Put these hyperlinks (for above fields) , in your index page :

code:

<br>
1.<a href="showforum.php?link=satire">Satire Stories</a>
<br>
<br>
2.<a href="showforum.php?link=drama">Drama Stories</a>
<br>
<br>
3.<a href="showforum.php?link=tragic">Tragic Stories</a>
<br>
<br>
4.<a href="showforum.php?link=joke">Jokes</a>
<br>
<br>
5.<a href="showforum.php?link=others">other not listed catagories</a>

Here we add the variable "link" to our url address. The user is directed to the common page "showforum.php" and there , base on the variable "link" the appropriate posts are shown.
Now , build a new php file , rename it to "showforum.php" and put the following codes in it.

code:

<?php
include "auth.inc"; // we check that if user has loged in or not
include "funcs.php"; // the functions look like : connect (to connect to the database) and creatcode (for verification text) can be put in a file and then we include that file wherever it is required. Here we want to summon the function "get_pages_html". This function produces page number links. If we have 40 posts under a field just 10 of them will be shown on each page and to visit the next 10 posts , the user should go to page 2. To know about this function go to :

http://webprogram4beginners.blogspot.com/2011/04/how-to-show-page-number-for-forum.html

?>

<?php
$forumlink =  $_SERVER["REQUEST_URI"]; // this is not needed hahaha

// first extract the variable "link" , and put it in a local variabe.

$forumlink = $_GET["link"]; // the field of the forum that is sent from the index page
?>
<a href="logout.php">log out</a>
<br>

// the following html codes show a menu-bar on the page . they have been created by Frontpage . You can omit them.

<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title> <?php echo  $forumlink;  ?> </title>
</head>
<body bgcolor="#99FF66" >
<table border="0" cellpadding="0" cellspacing="0" width="1055" height="625">
 <!-- MSTableType="layout" -->
 <tr>
  <td valign="top" colspan="3" height="148">
  <!-- MSCellType="ContentHead" -->
  <p align="center">
&nbsp;
<br>
<!--webbot bot="Navigation" S-Type="sequence" S-Orientation="horizontal" S-Rendering="graphics" S-Theme="poetic 0000" B-Include-Home="FALSE" B-Include-Up="FALSE" U-Page="sid:1001" --><a href="index.php"><img src="_derived/index.php_cmp_poetic000_hbtn.gif" width="154" height="37" border="0" alt="index.php" align="middle"></a> <a href="about.php"><img src="_derived/about.php_cmp_poetic000_hbtn.gif" width="154" height="37" border="0" alt="about.php" align="middle"></a> <a href="search.php"><img src="_derived/search.php_cmp_poetic000_hbtn.gif" width="154" height="37" border="0" alt="search.php" align="middle"></a><!--webbot bot="Navigation" i-checksum="38819" endspan --><br>
&nbsp;</p>
  <p><font size="6"><b> <?php echo  $forumlink;  ?> </b></font></td>

 </tr>
 <tr>
  <td valign="top" width="300">
  <!-- MSCellType="NavBody" -->

// the codes here shows a button to create a new post on the forum it is described under "how to add newtopic ability to a forum" post.

<FORM ACTION="newtopic.php" METHOD=POST>
<INPUT TYPE="hidden" NAME="originforum"    VALUE= "<?php echo $forumlink ?>"  >
the button redirects you to the form text box
<BR>
<INPUT TYPE="SUBMIT" NAME="BUTTON_new_topic" VALUE="add_new_story">
</FORM>
<br>
<br>
<br>
<font size="3"><b> main titles </b></font>
<?php
echo"
<br>

// the following is a menu of the fields in our website.
<br>

1.<a href=\"showforum.php?link=satire\">satire</a>
<br>
<br>
2.<a href=\"showforum.php?link=drama\">drama</a>
<br>
<br>
3.<a href=\"showforum.php?link=tragic\">tragic</a>
<br>
<br>
4.<a href=\"showforum.php?link=joke\">joke</a>
<br>
<br>
5.<a href=\"showforum.php?link=others\">others</a>
";
?>
<br>

  &nbsp;</td>
  <td valign="top" width="747">
  <!-- MSCellType="ContentBody" -->
  <p align="justify"><b><font size="4">
<br>
<br>
<br>
<?php
connect();
$sql = "SELECT * FROM topics WHERE field='$forumlink' "; // extract all of the posts in the forum field

$SearchResult = mysql_query($sql);
$TotalResults = mysql_num_rows($SearchResult);
$num_show_post = 20; //select an even number for the number of posts are showed in a page
if($TotalResults%2 == 0){

// based on the number of results we calculate the number of pages that is needed to show the results

$page_num = intval($TotalResults/$num_show_post); // "intval" returns the integer value of its variable

}else{
$page_num = intval($TotalResults/$num_show_post)+1;
}
$p = $_GET["p"]; // the current page number
$page_num = $GLOBALS['page_num']; // this line is not needed , you can omit it , it changes "$page_num" into a global variable.


if ($p == "")
$p = 1;
$counter = $TotalResults - (($p-1)*$num_show_post);  // based on the page number and number of posts to show on a page , we calculate this counter

for($i = $counter - 1; $i != $counter - $num_show_post -1; $i-- )


// by the calculated counter , show the appropriate posts on a page

{
$TextTitle = mysql_result($SearchResult, $i, 3);
$Textauthor = mysql_result($SearchResult, $i, 0);
$Textlink = mysql_result($SearchResult, $i, 5);

echo "<a href=\"showtopic.php?Textlink=" .$Textlink. " \">" . $TextTitle . "</a>"; // make a hyper link to the post that is clicked

echo "<br> <br>";
}
?>
</td>
  <td valign="top" height="427" width="147">


  <!-- MSCellType="NavBody2" -->
  &nbsp;</td>
 </tr>
 <tr>
  <td valign="top" colspan="3" height="50">

  <!-- MSCellType="ContentFoot" -->
<br>
<br>
<p align="center">
  <?php
  echo get_pages_html(); // the page number function "get_pages_html" is summoned here.

  ?>
  &nbsp;</td>
 </tr>
</p>
</table>
</body>
</html>
<p>
<br>
</p>
<html dir="ltr">

Enough comments has been added to the codes so there's no more need to explain.
The resulting forum page is look like :



If you don't want to go over all of my weblog you may need to read the following posts to understand the current post :

http://webprogram4beginners.blogspot.com/2011/04/how-to-show-page-number-for-forum.html

http://webprogram4beginners.blogspot.com/2011/02/download-php-codes-of-complete-forum.html

http://webprogram4beginners.blogspot.com/2011/02/how-to-add-variable-to-url-adress.html

http://webprogram4beginners.blogspot.com/2011/02/php-orders-to-work-with-database-and.html

3 comments:

  1. Excellent blog, I wish to share your post with my folks circle. It’s really helped me a lot, so keep sharing post like this
    Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune

    ReplyDelete
  2. Lucky Club: The lucky club of gambling in Malaysia
    Lucky Club is a luckyclub.live brand new social casino located in Malaysia. Our goal is to give every person a chance to win money,  Rating: 7.9/10 · ‎6,889 votes

    ReplyDelete
  3. Thank you for sharing your awesome and valuable article this is the best blog for the students they can also learn.
    https://lookobeauty.com/best-interior-designer-in-gurgaon/

    ReplyDelete