Jump to content

making my forum more advanced..


astralaaron

Recommended Posts

On more advanced forums when alot of people reply it seperates the posts onto different pages.. how when I get a certain amount of reply's can I seperate them into different pages so the one page does not get HUGE you guys know what I am asking here?if you can answer thanks..is this something very complicated?

Link to comment
Share on other sites

Do you pagination? Example of it here. 28 pages I think it is at that example.
something like that, its a message forum like this one.. just not as fancy..when like 10 or 15 posts fill up the first page I want it to start posting on the next..like you had the numbers on the bottom (previous 1, 2, 3, etc.. next)
Link to comment
Share on other sites

One solution (though probably not the most efficient one), is making an SQL query to the database to get the number of posts.Then you determine how many pages you need, ie, you have 100 posts split in groups of 15, you need 7 pages -> 100 / 15 = 7 (rounded up)When showing the posts, you limit it to a maximum of 15, and you start on the post number <page>*15Hope it was clear enough :)

Link to comment
Share on other sites

One solution (though probably not the most efficient one), is making an SQL query to the database to get the number of posts.Then you determine how many pages you need, ie, you have 100 posts split in groups of 15, you need 7 pages -> 100 / 15 = 7 (rounded up)When showing the posts, you limit it to a maximum of 15, and you start on the post number <page>*15Hope it was clear enough :)
sounds like what I need to do, I do not know how to do that though !
Link to comment
Share on other sites

Use variables to tell you what page you are on. show_thread.php?page=2If you want 15 per page, and you know you are on page 2, you need to get posts 16-30. So, the range is ($page+1) to ($page + $per_page). You can use the LIMIT clause in SQL to get only those.$per_page = 15;$start = $page + 1;SELECT .... LIMIT {$start}, {$per_page}That will get $per_page number of rows, starting at row $start.

Link to comment
Share on other sites

Use variables to tell you what page you are on. show_thread.php?page=2If you want 15 per page, and you know you are on page 2, you need to get posts 16-30. So, the range is ($page+1) to ($page + $per_page). You can use the LIMIT clause in SQL to get only those.$per_page = 15;$start = $page + 1;SELECT .... LIMIT {$start}, {$per_page}That will get $per_page number of rows, starting at row $start.
now this sounds like the way to go.I am not exactly sure how to put this onto my page but It gives me a better understanding! thank you.
Link to comment
Share on other sites

I just realized I can't add.

If you want 15 per page, and you know you are on page 2, you need to get posts 16-30. So, the range is ($page+1) to ($page + $per_page).
That would be 3 to 17, not 16 to 30. The correct range is:((($page - 1) * $per_page) + 1) to ($page * $per_page)So, the same code above should be this:$per_page = 15;$start = (($page - 1) * $per_page) + 1;SELECT .... LIMIT {$start}, {$per_page}
Link to comment
Share on other sites

Okay here is my "viewtopic" page.. how would I add that into this page to make it post a certain number of posts on each page and then start on the next page???if someone can help me with this then my forum will be complete! and I would be very greatfull!thanks!

<?php// Start sessionsession_start();// Check if the user already is logged inif ((!isset( $_SESSION['loggedin'] )) ||    (!$_SESSION['loggedin'])) {    header( 'Location: main_login.php' );    exit();}?><?php$host="localhost";$username="root"; $password="******";$db_name="multiforum";$tbl_name="forum1_question"; // Connect to server and select databse.mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");// get value of id that sent from address bar $id=$_GET['id'];$sql="SELECT * FROM $tbl_name WHERE id='$id'";$result=mysql_query($sql);$rows=mysql_fetch_array($result);?><center><a href="main_forum1.php"><strong>Main Forum</strong></a></center><table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"><tr><td><table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="1" bgcolor="#FFFFFF"><tr><td bgcolor="#F8F7F1"><strong><?php echo $rows['topic']; ?></strong></td></tr><tr><td bgcolor="#F8F7F1"><?php echo wordwrap($rows['detail'], 26, "\n", true); ?></td></tr><tr><td bgcolor="#F8F7F1"><strong>By :</strong> <?php echo $rows['name']; ?> <strong>Email : </strong><?php echo $rows['email'];?></td></tr><tr><td bgcolor="#F8F7F1"><strong>Date/time : </strong><?php echo $rows['datetime']; ?></td></tr></table></td></tr></table><BR><?php$tbl_name2="forum1_answer"; // Switch to table "forum_answer" $sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id'";$result2=mysql_query($sql2);while($rows=mysql_fetch_array($result2)){?><table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"><tr><td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"><tr><td bgcolor="#F8F7F1"><strong>ID</strong></td><td bgcolor="#F8F7F1">:</td><td bgcolor="#F8F7F1"><?php echo $rows['a_id']; ?></td></tr><tr><td width="18%" bgcolor="#F8F7F1"><strong>Name</strong></td><td width="5%" bgcolor="#F8F7F1">:</td><td width="90%" bgcolor="#F8F7F1"><?php echo $rows['a_name']; ?></td></tr><tr><td bgcolor="#F8F7F1"><strong>Email</strong></td><td bgcolor="#F8F7F1">:</td><td bgcolor="#F8F7F1"><?php echo $rows['a_email']; ?></td></tr><tr><td bgcolor="#F8F7F1"><strong>Answer</strong></td><td bgcolor="#F8F7F1">:</td><td width="90%" bgcolor="#F8F7F1" width="50%"><?php echo $rows['a_answer']; ?></td></tr><tr><td bgcolor="#F8F7F1"><strong>Date/Time</strong></td><td bgcolor="#F8F7F1">:</td><td width="90%" bgcolor="#F8F7F1"><?php echo $rows['a_datetime']; ?></td></tr></table></td></tr></table><br><?php}$sql3="SELECT view FROM $tbl_name WHERE id='$id'";$result3=mysql_query($sql3);$rows=mysql_fetch_array($result3);$view=$rows['view'];// if have no counter value set counter = 1if(empty($view)){$view=1;$sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'";$result4=mysql_query($sql4);}// count more value$addview=$view+1;$sql5="update $tbl_name set view='$addview' WHERE id='$id'";$result5=mysql_query($sql5);mysql_close();?><BR><table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"><tr><form name="form1" method="post" action="add_answer1.php"><td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"><tr><td width="18%"><strong>Name</strong></td><td width="3%">:</td><td width="79%"><?php echo ($_SESSION['user']); ?><input name="a_name" type="text" id="a_name" size="45" value="<?php echo ($_SESSION['user']); ?>" style="visibility=hidden;" /></td></tr><tr><td><strong>Email</strong></td><td>:</td><td><?php echo ($_SESSION['email']); ?><input name="a_email" type="text" id="a_email" size="45" value="<?php echo ($_SESSION['email']); ?>" style="visibility : hidden;" /></td></tr><tr><td valign="top"><strong>Answer</strong></td><td valign="top">:</td><td><textarea wrap="hard" name="a_answer" cols="100" rows="10" id="a_answer"></textarea></td></tr><tr><td> </td><td><input name="id" type="hidden" value="<?php echo $id; ?>"></td><td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td></tr></table></td></form></tr></table>

Link to comment
Share on other sites

Well, first on the top of the page you want to get the page variable from the URL, the same way you are getting the ID from it now. If the page variable is not set in the URL, then it should default to 1. Once you get the page, declare the other variables I posted above:$per_page = 15;$start = (($page - 1) * $per_page) + 1;Then, apparently, this is your SQL query to get all the records:$sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id'";So you want to add the LIMIT clause to the SQL statement:$sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id' LIMIT {$start}, {$per_page}";That will only get as many records as you need, and it will start at whichever record should be first. Then you need to figure out if you need a back or next link on the page, wherever you want that to go. You would need a back link if $page were greater then 1. You would need a next link if there are more rows then whatever $start + $per_page is. So to give the links for next and back, you would find out how many rows match the query, you can do that like this:$sql="SELECT COUNT(id) AS num FROM $tbl_name2 WHERE question_id='$id'";The "num" field would tell you how many rows match. If the row count is greater then $start + $per_page, then you need a next link. The next and back links need to have the page variable in them, with 1 either added or subtracted for the next and back, and you also need to pass the id in the URL, and anything else the page needs.Also, it's not safe to put anything from $_GET, $_POST, or $_COOKIE directly into a SQL statement like you do with the $id variable. Someone can easily write some SQL code as the value of id and you would execute it, they could delete your whole database or log in as admin or whatever they want to do. If $id is a number, and if it is then you don't need quotes around it in the SQL statement, then you would use intval to clean it if it is an integer, or floatval if it is a decimal number. If it is a string, then you would need to use mysql_real_escape_string to clean it. But either way, you need to clean it before you use it in the SQL statement.

Link to comment
Share on other sites

Justsomeguy thanks man this is good stuff.Just wondering, where can they enter the SQL to manipulate my database?? in my textfield? or in the address bar?I dont know about the intval I am going to see if php.net will explain how to use that to me.--------------------Okay I went to php.net/intval but it is a little bit confusing to me,do I clean it up during the $id=$_GET[id];or during the SQL $sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id=$id";?? if so how would I even write that?

Link to comment
Share on other sites

okay I tried doing this.. because I could not figure out how to get a page variableon the main forum page where it lists topics i did this:$pg = 1;then where you click on the topic I wrote this<a href="mmabjj_viewtopic.php?id=<?php echo $rows['id'];?>page=<?php echo $pg; ?>">looks like this:http://localhost/vikingbjj/mmabjj_viewtopic.php?id=11page=1and it made it so there was SQL errorsso i tried doing this: <a href="mmabjj_viewtopic.php?id=<?php echo $rows['id'];?>?page=<?php echo $pg; ?>">it lookslike thishttp://localhost/vikingbjj/mmabjj_viewtopic.php?id=11?page=1both of them made SQL errors and would not let me view the topic.. I have no clue how to make the page variable as you can see! please help!thanks

Link to comment
Share on other sites

First the problem with intval:It doesn't mather where you put it, but I would put it by $id = $_GET...:

$id = intval( $_GET['id'] );

To put it in the query use this:

$sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id=" . intval($id);

To add a value to the querystring you need to use a ampersand (&): index.php?id=1&page=2When you didn't use a ampersand nor intval yot get an error because the SQL would look like this

INSERT INTO the_table(view) VALUES('view') WHERE id=1page=2

(Not sure on what you want to do with this query, it doesn't look good to me...)(Not sure what hapends if there's two q-marks in the querystring)Good Luck and Don't Panic! ;?)

Link to comment
Share on other sites

First the problem with intval:It doesn't mather where you put it, but I would put it by $id = $_GET...:
$id = intval( $_GET['id'] );

To put it in the query use this:

$sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id=" . intval($id);

To add a value to the querystring you need to use a ampersand (&): index.php?id=1&page=2When you didn't use a ampersand nor intval yot get an error because the SQL would look like this

INSERT INTO the_table(view) VALUES('view') WHERE id=1page=2

(Not sure on what you want to do with this query, it doesn't look good to me...)(Not sure what hapends if there's two q-marks in the querystring)Good Luck and Don't Panic! ;?)

thanks
Link to comment
Share on other sites

I just realized I can't add.That would be 3 to 17, not 16 to 30. The correct range is:((($page - 1) * $per_page) + 1) to ($page * $per_page)So, the same code above should be this:$per_page = 15;$start = (($page - 1) * $per_page) + 1;SELECT .... LIMIT {$start}, {$per_page}
please explain how to make the page variable!
Link to comment
Share on other sites

I tried changing the sql to:$sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id' LIMIT {$start}, {$per_page}";when I do that it returns this:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\vikingbjj\mmabjj_viewtopic.php on line 104I have to not be doing something right when making a page variable.. thats the part I dont have a clue about!

Link to comment
Share on other sites

Hi!Try this:

if  (isset($_GET['page']))		$page = intval( $_GET['page'] );else		$page = 1;$per_page = 15;$start = (($page - 1) * $per_page); // The "+ 1" shouldn't be there..

And then just

$sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id' LIMIT $start, $per_page";

As long as all the variables is set and the values is right, then it should workThe + 1 tells MySQL to skip the first post...You wouldn't need the { } around the variables in the string.

Link to comment
Share on other sites

Hi!Try this:
if  (isset($_GET['page']))		$page = intval( $_GET['page'] );else		$page = 1;$per_page = 15;$start = (($page - 1) * $per_page); // The "+ 1" shouldn't be there..

And then just

$sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id' LIMIT $start, $per_page";

As long as all the variables is set and the values is right, then it should workThe + 1 tells MySQL to skip the first post...You wouldn't need the { } around the variables in the string.

I will try this thanks.. I still do not think I am doing the page variable correctly!all I did to do that was on the main forum page.. i did this $pg = 1;and on the link where you click to view the topic i just did this:<a href="<?php echo "viewtopic.php?id=" . $row[id] . "&page="$pg"; >?>is that what I was suposed to do? or am I going about making page=1 show up in the URL all wrong?please help!!
Link to comment
Share on other sites

when The user adds an answer it sends the variables here to this page..I think something needs to be done here also:<?phpinclude('safe.php');// Connect to server and select databse.mysql_connect("localhost", "root", "******")or die("cannot connect"); mysql_select_db("vikingbjj")or die("cannot select DB");// Get value of id that sent from hidden field $id=$_POST[id];// Find highest answer number. $sql="SELECT MAX(a_id) AS Maxa_id FROM mmabjj_answer WHERE question_id=$id";$result=mysql_query($sql);$rows=mysql_fetch_array($result);// add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 if ($rows) {$Max_id = $rows['Maxa_id']+1;}else {$Max_id = 1;}// get values that sent from form $a_name=$_POST['a_name'];$a_email=$_POST['a_email'];$a_answer=safe($_POST['a_answer']); $datetime=date("d/m/y H:i:s"); // create date and time // Insert answer $sql2="INSERT INTO mmabjj_answer(question_id, a_id, a_name, a_email, a_answer, a_datetime)VALUES($id, '$Max_id', '$a_name', '$a_email', '$a_answer', '$datetime')";$result2=mysql_query($sql2);if($result2){header("location:mmabjj_viewtopic.php?id=$id");// If added new answer, add value +1 in reply column $sql3="UPDATE mmabjj_question SET reply='$Max_id' WHERE id=$id";$result3=mysql_query($sql3);}else {echo "ERROR";}mysql_close();?>

Link to comment
Share on other sites

Well, I don't think you did like that, cause tha's not valid, but it could look like this:

$total_pages = $total_count / $per_page;for ($i=1; $i <= $total_pages; $i++) {   if ($i == $page)	   echo '<span class="bold">';   else	   echo '<a href="viewtopic.php?id=' . $id . '&page=' . $i .'">';   echo $i;   if ($i == $page)	   echo '</span>';   else	   echo '</a>';   echo '  ';}

That would work ok!ps Sorry if I misunderstood you, but you can also see how to create the link from the code... dsEDIT (as you posted a new one when I was writing this :) ), this is gonna be short as I'm going to bed soon, but why do you get the max id from the db and then give the post an id yourself, why don't you leave that to MySQL, its much mor esimplier, just set auto_increase on the field (and prmary key... but I guess that's already done)Good Luck and Don't Panic!

Link to comment
Share on other sites

Hi!Try this:
if  (isset($_GET['page']))		$page = intval( $_GET['page'] );else		$page = 1;$per_page = 15;$start = (($page - 1) * $per_page); // The "+ 1" shouldn't be there..

And then just

$sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id' LIMIT $start, $per_page";

As long as all the variables is set and the values is right, then it should workThe + 1 tells MySQL to skip the first post...You wouldn't need the { } around the variables in the string.

no luck... it is returning this:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\vikingbjj\mmabjj_viewtopic.php on line 104am I suposed to have something setup in my database to get the page# ??
Link to comment
Share on other sites

Well, I don't think you did like that, cause tha's not valid, but it could look like this:
<?php// Start sessionsession_start();// Check if the user already is logged in if ((!isset( $_SESSION['loggedin'] )) ||    (!$_SESSION['loggedin'])) {    header( 'Location: login.php' );    exit();}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD>	<TITLE>MMA and BJJ message forum</TITLE> <META name="abstract" content=""> <META name="description" content=""> <META name="keywords" content=""> <META name="Revisit-After" content="10"> <META HTTP-EQUIV="Content-Language" content="EN"> <META name="distribution" content="global"> <link rel="stylesheet" type="text/css" href="forum.css"> <link rel="stylesheet" type="text/css" href="input.css"> </HEAD><BODY><div id="top"><?php if ((!isset( $_SESSION['loggedin'] )) ||    (!$_SESSION['loggedin'])) { echo "<p class=\"log\">Welcome Guest <a href=\"login.php\">Log In</a>";  } else { echo ("<p class=\"log\">Welcome ". ($_SESSION['user']) . " <a href=\"logout.php\">log out</a></p>");  } ?></div><div id="sitemap"><p><a class="menu" href="index.php" title="VikingBJJ home page">VikingBJJ.com</a> >>> <a class="menu" href="mmabjj.php" title="Back to MMA & BJJ forum">MMA & BJJ Forum</a></p></div><div id="forumbody"><?php$host="localhost"; // Host name $username="root"; // Mysql username $password="***********"; // Mysql password $db_name="vikingbjj"; // Database name $tbl_name="mmabjj_question"; // Table name // Connect to server and select databse.mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");// get value of id that sent from address bar $id=intval($_GET[id]);$sql="SELECT * FROM $tbl_name WHERE id=$id";$result=mysql_query($sql);$rows=mysql_fetch_array($result);?><table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFF00"><tr><td><table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="1" "bgcolor="#000055"><tr><td bgcolor="#000055"><p><?php echo $rows['topic']; ?></p></td></tr><tr><td bgcolor="#000055"><p><?php echo wordwrap($rows['detail'], 26, "\n", true); ?></p></td></tr><tr><td bgcolor="#000055"><p>By : <?php echo $rows['name']; ?> Email : <?php echo $rows['email'];?></p></td></tr><tr><td bgcolor="#000055"><p>Date/time : <?php echo $rows['datetime']; ?></td></tr></table></td></tr></table><BR><?php$tbl_name2="mmabjj_answer"; // Switch to table "forum_answer" $sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id' LIMIT";$result2=mysql_query($sql2);while($rows=mysql_fetch_array($result2)){?><table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFF00"><tr><td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFF00"><tr><td bgcolor="#000055" align="right"><p>ID:</p></td><td bgcolor="#000055"><p><?php echo $rows['a_id']; ?></p></td></tr><tr><td width="10%" bgcolor="#000055" align="right"><p>Name:</p></td><td width="90%" bgcolor="#000055"><p><?php echo $rows['a_name']; ?></p></td></tr><tr><td width="10%" bgcolor="#000055" align="right"><p>Email:</p></td><td bgcolor="#000055"><p><?php echo $rows['a_email']; ?></p></td></tr><tr><td width="10%" bgcolor="#000055" align="right"><p>Reply:</p></td><td width="90%" bgcolor="#000055" width="50%"><p><?php echo $rows['a_answer']; ?></p></td></tr><tr><td width="10%" bgcolor="#000055" align="right"><p>Date/Time:</p></td><td width="90%" bgcolor="#000055"><p><?php echo $rows['a_datetime']; ?></p></td></tr></table></td></tr></table><br><?php}$sql3="SELECT view FROM $tbl_name WHERE id=$id";$result3=mysql_query($sql3);$rows=mysql_fetch_array($result3);$view=$rows['view'];// if have no counter value set counter = 1if(empty($view)){$view=1;$sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id=$id";$result4=mysql_query($sql4);}// count more value$addview=$view+1;$sql5="update $tbl_name set view='$addview' WHERE id=$id";$result5=mysql_query($sql5);mysql_close();?><table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFF00"><tr><form name="form1" method="post" action="mmabjj_answer.php"><td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#000055"><tr><td width="18%" bgcolor="#000055"><p>Name:</td><td width="3%" bgcolor="#000055"> </td><td width="79%" bgcolor="#000055"><p><?php echo ($_SESSION['user']); ?><input name="a_name" type="text" id="a_name" size="45" value="<?php echo ($_SESSION['user']); ?>" style="visibility=hidden;" /></td></tr><tr><td bgcolor="#000055"><p>Email:</td><td bgcolor="#000055"> </td><td><p><?php echo ($_SESSION['email']); ?><input name="a_email" type="text" id="a_email" size="45" value="<?php echo ($_SESSION['email']); ?>" style="visibility : hidden;" /></td></tr><tr><td valign="top" bgcolor="#000055"><p>Reply:</p></td><td valign="top" bgcolor="#000055"> </td><td><textarea class="style" wrap="hard" name="a_answer" cols="80" rows="10" id="a_answer"></textarea></td></tr><tr><td> </td><td bgcolor="#000055"><p><input name="id" type="hidden" value="<?php echo $id; ?>"><input name="page" type="hidden" value="<?php echo $page; ?>"></p></td><td bgcolor="#000055"align="center"><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td></tr></table></td></form></tr></table></div></BODY></HTML>

and this is my answer.php that the reply variables are sent to..:

<?phpinclude('safe.php');// Connect to server and select databse.mysql_connect("localhost", "root", "***********")or die("cannot connect"); mysql_select_db("vikingbjj")or die("cannot select DB");// Get value of id that sent from hidden field $id=$_POST[id];// Find highest answer number. $sql="SELECT MAX(a_id) AS Maxa_id FROM mmabjj_answer WHERE question_id=$id";$result=mysql_query($sql);$rows=mysql_fetch_array($result);// add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 if ($rows) {$Max_id = $rows['Maxa_id']+1;}else {$Max_id = 1;}// get values that sent from form $a_name=$_POST['a_name'];$a_email=$_POST['a_email'];$a_answer=safe($_POST['a_answer']); $datetime=date("d/m/y H:i:s"); // create date and time // Insert answer $sql2="INSERT INTO mmabjj_answer(question_id, a_id, a_name, a_email, a_answer, a_datetime)VALUES($id, '$Max_id', '$a_name', '$a_email', '$a_answer', '$datetime')";$result2=mysql_query($sql2);if($result2){header("location:mmabjj_viewtopic.php?id=$id");// If added new answer, add value +1 in reply column $sql3="UPDATE mmabjj_question SET reply='$Max_id' WHERE id=$id";$result3=mysql_query($sql3);}else {echo "ERROR";}mysql_close();?>

can you show me where this stuff needs to be?

Link to comment
Share on other sites

this is my main forum code also where you click on which topic to view:

<?php// Start sessionsession_start();// Check if the user already is logged inif ((!isset( $_SESSION['loggedin'] )) ||    (!$_SESSION['loggedin'])) {    header( 'Location: login.php' );    exit();}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD>	<TITLE>MMA and BJJ message forum</TITLE> <META name="abstract" content=""> <META name="description" content=""> <META name="keywords" content=""> <META name="Revisit-After" content="10"> <META HTTP-EQUIV="Content-Language" content="EN"> <META name="distribution" content="global"> <link rel="stylesheet" type="text/css" href="forum.css"> </HEAD><BODY><div id="top"><?php if ((!isset( $_SESSION['loggedin'] )) ||    (!$_SESSION['loggedin'])) { echo "<p class=\"log\">Welcome Guest <a href=\"login.php\">Log In</a>";  } else { echo ("<p class=\"log\">Welcome ". ($_SESSION['user']) . " <a href=\"logout.php\">log out</a></p>");  } ?></div><div id="sitemap"><p><a class="menu" href="index.php" title="VikingBJJ home page">VikingBJJ.com</a></p></div><div id="forumbody"><?php$host="localhost"; // Host name $username="root"; // Mysql username $password="********"; // Mysql password $db_name="vikingbjj"; // Database name $tbl_name="mmabjj_question"; // Table name // Connect to server and select databse.mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");$pg = 1;$sql="SELECT * FROM $tbl_name ORDER BY id DESC";// OREDER BY id DESC is order result by descending $result=mysql_query($sql);?><table width="100%" border="0" bordercolor="#ffff00" align="center" cellpadding="3" cellspacing="1" bgcolor="#ffff00"><tr><td width="6%" align="center" bgcolor="#000055"><strong><p>#</p></strong></td><td width="53%" align="center" bgcolor="#000066"><strong><p>MMA & BJJ</p></strong></td><td width="15%" align="center" bgcolor="#000055"><strong><p>Views</p></strong></td><td width="13%" align="center" bgcolor="#000066"><strong><p>Replies</p></strong></td><td width="13%" align="center" bgcolor="#000055"><strong><p>Date/Time</p></strong></td></tr><?phpwhile($rows=mysql_fetch_array($result)){ // Start looping table row ?><tr><td align="center" bgcolor="#000044"><p><?php echo $rows['id']; ?></p></td><td VALIGN="middle" align="left" bgcolor="#000044"><a href="<?php echo "mmabjj_viewtopic.php?id=" . $rows['id'] ."&page=$pg"; ?>"><?php echo $rows['topic']; ?></a></td><td align="center" bgcolor="#000044"><p><?php echo $rows['view']; ?></p></td><td align="center" bgcolor="#000044"><p><?php echo $rows['reply']; ?></p></td><td align="center" bgcolor="#000044"><p><?php echo $rows['datetime']; ?></p></td></tr><?php// Exit looping and close connection }mysql_close();?><tr><td colspan="1" align="left" bgcolor="#000066"> </td><td colspan="1" align="center" bgcolor="#000066"><a href="mmabjj_newtopic.php"><p>Create New Topic</p> </a></td><td colspan="4" align="right" bgcolor="#000066"> </td></tr></table></div></BODY></HTML>

Link to comment
Share on other sites

From what you posted, this is your SQL statement:$sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id' LIMIT";That it not a valid statement, that's why you are getting the error. The LIMIT clause requires 2 parameters after that for the starting row and the number of rows, that's what the $start and $per_page variables are for.As for getting the page variable, I would prefer to do it like this:

$page = intval($_GET['page']);if ($page < 1)  $page = 1;

I don't understand what your confusion is with the page variable. That code, and the code that Mr. Chisol posted, is how you get it from the URL. You already showed how you write it to the URL, so I don't understand what the confusion is about. For the next and back links, you want to print either $page + 1 or $page - 1 in the URL.It might be that a forum is a bit too much to bite off without learning the basics first. You might want to just make a page that gets form input and sends an email, and then a page that writes it to a file, and maybe adds it to a database. Once you understand how to process a form, then something like a forum might be a little more realistic. But if you're trying to make a forum and you don't know how to pass variables from one page to another, you might want to think about reading some more about how to use PHP before you tackle a project like this.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...