Jump to content

My Comment System With Pagination.


MrFish

Recommended Posts

I'm very happy with this. Please check it out and post something. Also look at my code and tell me if you think it's good. If you like it you can steal it from me :)http://mrfishtests.byethost17.com/paginationtest.php?page=1

<html><head><title>Pagination Test 1</title><style type="text/css">A:link{text-decoration: none;font-family: verdana;color: #4BA0BB;font-weight: 700;}A:visited{text-decoration: none;font-family: verdana;color: #4BA0BB;font-weight: 700;}A:active{text-decoration: none;font-family: verdana;color: #4BA0BB;font-weight: 700;}A:hover{text-decoration: none;font-family: verdana;color: #4BA0BB;font-weight: 700;}</style></head><body style="background-color:#DFEAFB; margin: 0px;"><div id="wrapper" style="width: 600px; margin: 0px auto; padding: 20px; background-color: #FFEAC9"><form action="paginationtest1_handler.php" method="POST"><input type="text" style="width: 485px; margin: 0px 10px 0px 5px; float: left; padding: 5px; background-color: #fff; border: 1px solid #A7A6AA;" name="name" value="Name"><input type="submit" style="float: left; width: 95px; margin: 0px 5px 0px 0px; background-color: #C9EBCA; border: 1px solid #7FCF81; padding: 5px;" value="Comment!"><textarea name="comment" style="width: 600px; margin: 10px 0px 10px 0px; height: 100px; padding: 10px; font-family: verdana; background-color: #fff; border: 1px solid #A7A6AA;">Please leave a comment!</textarea></form><?php$page = $_GET['page'];if($page == null || $page < 1 || $page == ""){	$page = 1;}$limit = $_GET['limit'];if($limit == null || $limit == ""){	$limit = 10;}$orderby = $_GET['orderby'];if($orderby == null || $orderby == ""){	$orderby = 'comment_number';}$order = $_GET['order'];if($order == null || $order == ""){	$order = 'DESC';}$con = mysql_connect('server', 'username', 'password');mysql_select_db('b17_3648160_testdatabase', $con);/* How many comments exist? */$query = "SELECT * FROM paginationtest";$run = mysql_query($query);$comment_count = mysql_affected_rows();/* Start on which comment? */$end = $page - 1;$end = $end*$limit;$end = $comment_count - $end + 1;$start = $end - 10;$query = "SELECT * FROM paginationtest WHERE comment_number BETWEEN $start AND $end ORDER BY $orderby $order LIMIT $limit";$run = mysql_query($query);while($results = mysql_fetch_array($run, MYSQL_ASSOC)){	echo '<div style="width: 600px; background-color: #C9EBCA; float: left;"><div id="name_and_date" style="width: 480px; padding: 10px; font-family: verdana; float: left;"><b><font style="color: #518755">' . $results['name'] . '</font></b><br /><i><font style="font-size: 12px; color: #5AC15C">' . $results['date'] . '</font></i></div><div id="post_count" style="width: 80px; padding: 10px; text-align: right; float: left; font-weight: 700; color: #518755">' . $results['comment_number'] . '</div></div><br />';	echo '<div style="width: 560px; background-color: #F7F7E3; padding: 20px; font-family: verdana; clear: both;"><font style="color: #9C9C8F">' . $results['comment'] . '</font></div><br /><br />';}	$previous = $page - 1;;$current = $page;$after = $page + 1;$end = $comment_count/$limit;$end = ceil($end);$url = $_SERVER['PHP_SELF'];echo '<div style="width: 590px; padding: 5px; background-color: #DFEEF3; font-family: verdana; text-align: center;">';/* First */if($current != 1 && $previous != 1){echo '<a href="' . $url . "?page=1" . '">First</a> ...';}/* Before */if($previous != 0){echo '<a href="' . $url . "?page=$previous" . '">' . $previous . '</a>, ';}/* Current */echo '<a href="' . $url . "?page=$current" . '">' . $current . '</a>';/* After */if($after != $current && $after != $end + 1){echo ', <a href="' . $url . "?page=$after" . '">' . $after . '</a>';}/* End */if ($end != $current){echo '... <a href="' . $url . "?page=$end" . '">' . $end . '</a>';}echo '</div>';?></div></body></html>

Link to comment
Share on other sites

On the whole yeah seems to work fine. can see a couple things that u might wanna change

/* How many comments exist? */$query = "SELECT * FROM paginationtest";$run = mysql_query($query);$comment_count = mysql_affected_rows();

if you are just gonna count the number of results, there isnt really anyneed to select every field from every row, might wanna use this

/* How many comments exist? */$query = "SELECT `comment_number` FROM paginationtest";$run = mysql_query($query);$comment_count = mysql_affected_rows();

it might speed up the query, especially as the database gets larger...also, when you click inside a text field it would be good if the initial value cleared on focus, can be done with javascript for example:

<script type="text/javascript" language="javascript">function clearText(thefield){if (thefield.defaultValue==thefield.value)	thefield.value = "";}</script><input name="id" type="text" value="Please leave a comment" onfocus="clearText(this)"/>

finnaly this is a bit pedantic but, you've put a new line break in your Please Leave a Comment text box content, should be like this:

<textarea name="comment" style="width: 600px; margin: 10px 0px 10px 0px; height: 100px; padding: 10px; font-family: verdana; background-color: #fff; border: 1px solid #A7A6AA;">Please leave a comment!</textarea>

these are sorta small details, but i hope it helps

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...