Hi all, I have this code, basically a user logs into my site and they get this page.
The problem I have is that the pagination isn't working, and I can figure out why. I dont get any errors.
Can you help please. If you need any more info, just shout. Ta muchly
Code: <?php
include("includes/dbconnect120-gem.php");
include("includes/db_auth_hp.php");
include("includes/functions.php");
$username = $result['username'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/templ8t.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/layout.css" rel="stylesheet" type="text/css" />
<link href="css/text.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<script language="javascript" type="text/javascript">
<!--
function showhide(id) {
if(document.getElementById(id).style.display == 'none') {
document.getElementById(id).style.display = 'block';
} else {
document.getElementById(id).style.display = 'none';
}
}
-->
</script
<!-- InstanceEndEditable -->
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
.H2 {
font-size: x-large;
font-family: Arial, Helvetica, sans-serif;
background-color: #FFFF00;
}
.link {color: #FFFF33}
-->
</style>
</head>
<body>
<div class="wrapper">
<div class="header">
</div>
<div class="body">
<!-- InstanceBeginEditable name="bodytext" -->
Hello, <?php echo ucwords($username); ?> you are now logged in.
<?php
// find out how many rows are in the table
$sql = "SELECT COUNT(*) FROM articles";
$result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
// number of rows to show per page
$rowsperpage = 1;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
//Gets news.
$sql = "SELECT * FROM articles ORDER BY ID DESC";
$result = mysql_query($sql);
//Displays the results.
while($row = mysql_fetch_array($result)){
$news_title = nl2br($row['Title']);
$news_subtitle = nl2br($row['SubTitle']);
$news_post = nl2br($row['Article']);
$post_id = $row['ID'];
echo $news_title;?>
<?php echo $news_subtitle; ?>
<?php echo $news_post; ?>
<!-- END DISPLAY NEWS -->
<?php
$csql = "SELECT comments.tstamp, login.username, comments.post
FROM comments
LEFT JOIN login
ON comments.userid = login.userid
WHERE comments.articleid = $post_id
ORDER BY comments.postid DESC";
$cquery = mysql_query($csql);
$ccount = mysql_num_rows($cquery);
if($ccount == 0) {
$comments_number = '<a href="comment.php?post='.$post_id.'" target="_self">No Comments</a>';
} else {
$comments_number = '<a href="#coms'.$post_id.'" onclick="showhide('c'.$post_id.'');">Comments('.$ccount.')</a>';
}
?>
<p class="right"><?php echo $comments_number; ?><a name="coms<?php echo $post_id; ?>"></a> </p>
<div style="display:none" id="<?php echo 'c'.$post_id; ?>" >
<?php
if($ccount != 0) {
while($crow = mysql_fetch_array($cquery)) {
$ctime = $crow['tstamp'];
$cusername = ucwords($crow['username']);
$cmessage = $crow['post'];
echo "<hr />n";
echo '<p><span class="bold">'.$cusername.':</span> '.nl2br($cmessage)."n";
echo '<br /><span class="bold">Posted: </span>';
if(timeago($ctime) == '') {
echo "Just.n";
}
elseif(strlen(timeago($ctime)) < 16) {
echo str_replace('and ', '', timeago($ctime)).'ago.</p>'."n";
} else {
echo timeago($ctime).'ago.</p>'."n";
}
}
$more = 'Leave a Comment';
echo '<p class="right"><a href="comment.php?post='.$post_id.'" target="_self">'.$more.'</a></p>';
}
?>
</div>
<?php
} // end while
/****** build the pagination links ******/
// range of num links to show
$range = 4;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
// echo forward link for lastpage
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/
?>
<!-- InstanceEndEditable --> </div>
<div class="sidebar">
<!-- MENU -->
<BR><?php
include "includes/menujs.js";
include "includes/menucss.css";
include "includes/menu.html";
?>
</p>
<p>
<!-- InstanceBeginEditable name="sidebar" -->
<div class="sidebartitle">
Latest News</div>
<div class="sidebartext">
</div>
<div class="sidebartitle">
Coming Soon </div>
<div class="sidebartext">
</div>
<!-- InstanceEndEditable --> </p>
</div>
</div>
<div class="clear"></div>
<div class="copyright">
<div align="center" class="style1">©Copyright 2010 Bradley Stoke Judo Club || Site Designed by Gem Gale || Site Hosted by <a href="http://www.wotwebsystems.com" class="link">WOT Web Systems</a></div>
</div>
</body>
<!-- InstanceEnd --></html>
Select Lists into MYSQL
Hello All, I am new to PHP @ 1 week. So borrowing code anywhere I can. I am making progress, but hit a snag. I have 2 list boxes, that I use to move items left to right. When I click submit I want
PHP Form to Variable.
Hi! I have written a HTML-form code in DreamWeaver CS3 (in a PHP doc) and I really need it to work soon :/I have a form:(<form name="form1" action=""
Effort Estimation Template for Steady State Support
Hi Everyone,
Retail terminologys not been altered after activing Retail System
Hi, All
Rand() help needed
Hi all,Can someone explain and give me a quick example of how I would go about this?I have 100 values in a database with colum headings of t_val and t_name. If I wanted to update all 100 of these
Install page
How do I make it so when a user submits information on the Install page, it'll right it into the correct file. I can do the forms and $_POST, but I need it so that it actually works.Current stuff in
Help with explandable category tree
I have the below query: SELECT l1.id as lev1_id,l2.id as lev2_id,l3.id as lev3_id,l1.category AS lev1, l2.category as lev2, l3.category as lev3 FROM categories AS l1LEFT JOIN categories AS l2 ON
javascript in php code causes page to display white
Hi All,Odd one this, I've got the following code (below) which is a simple log in form. The client wanted a pop to inform you when you've not completed a field and an asterix to appear.This is fine.
Problem with "dynamic" index page
Hi. I have one question. In my index.php page I have this kind of code:Code: // listaa sivut$pages = Array ("etusivu" => "etusivu.php",,"linkit" =>
DELETE FROM not working deletes wrong row
HelloI have the following code which i found but it doesnt work properly.. it comes up with a list of the items in the database e.g.item 1 - deleteitem 2 - delete item 3 - deletebut when i