Jump to content

Recommended Posts

Using the tutorial from php freaks i was able to get pagination working on my site. How ever there are a few changes id like to make. I would like to have it listed in 2 columns. The other problem that I'm having is when i attempt to add class="nav" to the next page link i get an error. Can a class be used in a php echo?

 

Here's what I have.

 

<?php  session_start(); 
$rank=$_SESSION['rank'];
$loggedinusername=$_SESSION['loggedinusername'];
$loggedinuseremail=$_SESSION['loggedinuseremail'];
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Drink To The Credits</title>
<link href="mainstyle.css" rel="stylesheet" type="text/css" />
</head>

<body class="background">
<div id="header"> <?php include_once"header.php" ?></div>

<div id="content">   

<?php

include"scripts/connect.php" ;

mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or trigger_error("SQL", E_USER_ERROR);

$sql = "SELECT COUNT(*) FROM movies WHERE type LIKE 'movie'";
$result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
$rowsperpage = 15;
$totalpages = ceil($numrows / $rowsperpage);


if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
   $currentpage = (int) $_GET['currentpage'];
} else {
   $currentpage = 1;
}
if ($currentpage > $totalpages) {
   $currentpage = $totalpages;
} 
if ($currentpage < 1) {
   $currentpage = 1;
} 

$offset = ($currentpage - 1) * $rowsperpage;
$sql = "SELECT title FROM movies ORDER BY title LIMIT $offset, $rowsperpage" ;
$result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR);

while ($list = mysql_fetch_assoc($result)) {
     ?>
<tr>
<td> <a class="nav" href=/rules.php?title=<?php echo urlencode($list['title']); ?>><?php echo $list['title']; ?></a> <br />
<?php
} 
$range = 3;

if ($currentpage > 1) {
   echo " <a href='<?php {$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
   $prevpage = $currentpage - 1;
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} 
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
   if (($x > 0) && ($x <= $totalpages)) {
      if ($x == $currentpage) {
         echo " [<b>$x</b>] ";
      } else {
         echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
      } 
   } 
} 
        
if ($currentpage != $totalpages) {
   $nextpage = $currentpage + 1;
    
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // built with a tutorial from php freaks
?>
</div>

<div id="sidecontent"><?php include_once"newmovies.php" ?></div>
<div id="footer"> <?php include_once"footer.php" ?></div>
</body>
</html>

 

Thank you in advance

Link to comment
https://forums.phpfreaks.com/topic/258433-pagination/
Share on other sites

This is the error i get

 

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /movies.php on line 76

 

Here is what i had for the next page link which is line 76

 

  
echo " <a class="nav" href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";

 

What is the problem with using php_self? And what should I be useing?

Link to comment
https://forums.phpfreaks.com/topic/258433-pagination/#findComment-1324905
Share on other sites

The problem is that you're using double quotes inside of a double-quoted string. Try:

 

echo " <a class='nav' href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";

 

 

As for the security issues with $_SERVER['PHP_SELF'], check out some of the links provided by the following Google search: http://www.google.com/search?q=security+issues+with+php_self+in+links

 

Note that a lot of focus seems to be placed on using PHP_SELF in forms, but there's an issue with using the variable to display things like links also.

 

Instead of using PHP_SELF, the page's filename could be explicitly stated.

 

echo " <a class='nav' href='your_page.php?currentpage=$nextpage'>></a> ";

Link to comment
https://forums.phpfreaks.com/topic/258433-pagination/#findComment-1324913
Share on other sites

Just to clarify about the security issue, try visiting your page using Firefox. When visiting the website though, change the address to:

 

www.yourwebsiteaddress.com/yourscript.php/'><script type="text/javascript">window.location="http:/\/www.google.com/"</script><!--

 

Note that "www.yourwebsiteaddress.com/yourscript.php" should be changed to the URL used to access your page. If typed correctly, it should redirect you to Google.

Link to comment
https://forums.phpfreaks.com/topic/258433-pagination/#findComment-1324915
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.