Unstoppable Domains

Pagination Problems....

Spaceship Spaceship
Watch

AllValley

Established Member
Impact
1
Hi there! making a portfolio page for my website, and the code seems to work. but the links for pagination do not show up :(

Here are the files I'm working with
Contents of the callid_port.php file
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Portfolio</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
	include('config.php');
// request text from all the jokes

	include('pagination.php');

	
			echo("<table class='prod' cellpadding='3' border='3'>");
			echo("<tr><td colspan='4'><h3 align='center'>Sort Portfolio By: <a href='id.html'>All</a> | <a href='dsnrs.html'>Designer</a> | <a href='live.html'>Live Sites</a></h3></td></tr>
				<tr>
						<td><h4 align='center'> Design Thumbnail </h4></td><td><h4 align='center'> Design Title </h4></td><td><h4 align='center'> Design Author </h4></td>
						<td><h4 align='center'> Design URL </h4></td>
				</tr>
						");
			
			
	while ( $row = mysql_fetch_array($result) ) {
		$id = $row["ID"];
		$dsnr = $row["dsnr"];
		$img = $row["img"];
		$live = $row["live"];
		$port_desc = $row["port_desc"];
		$href = $row["href"];
		$title = $row["title"];
		
		if (empty($row)) {
		echo("<h1>Coming Soon!</h1>"); }
		elseif($live==1){		
			$ahref = "<a href='" . $href . "' target='_blank'>" . $title . "</a> *Live Site!*" ;
			}else ( $ahref= "Not Live" );
			
		
		echo("<tr><td class='td2'>" . "<a href='/images/" . $img . "' target='_blank'><img width='90px' height='120px' src='/images/" . $img . "' title='Click For Larget Image' border='0' /></a>" . "</td><td class='td3'><p align='center'>"  . $title . "</p>"  .  "</td><td class='td4'>"  . $dsnr . "</td><td class='td5'>" . $ahref .  "</td></tr><tr><td colspan='4'><blockquote> <p align='left'>Design Description:</p>" . $port_desc . "</blockquote></td></tr>");
	}
	 include('pagination2.php');
	echo("</table>");
	;
	?>
</body>
</html>


Contents of pagination.php
Code:
<?

 $limit          = 5;               
    $query_count    = "SELECT count(*) FROM port";    
    $result_count   = mysql_query($query_count);    
    $totalrows      = mysql_num_rows($result_count);

    if(empty($page)){
        $page = 1;
    }
        

    $limitvalue = $page * $limit - ($limit);
    $query  = "SELECT * FROM port LIMIT $limitvalue, $limit";        
    $result = mysql_query($query) or die("Error: " . mysql_error());

    if(mysql_num_rows($result) == 0){
        echo("Nothing to Display!");
    }

    

   
    
	?>

Contents of pagination2.php
Code:
<?

if($page != 1){
        $pageprev = $page--;
        
        echo("<a href=\"callid_port.php&page=$pageprev\">PREV".$limit."</a> ");
    }else{
        echo("PREV".$limit." ");
    }

    $numofpages = $totalrows / $limit;
    
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"callid_port.php?page=$i\">$i</a> ");
        }
    }


    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"callid_port.php?page=$i\">$i</a> ");
        }
    }

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;
         
        echo("<a href=\"callid_port.php?page=$pagenext\">NEXT".$limit."</a>");
    }else{
        echo("NEXT".$limit);
    }
    
    mysql_free_result($result); 
	
	?>

It works, but the PREV and NEXT don't show up as links :s

Any Ideas? (Link To Page

TIA
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
For pagination, try:
PHP:
<?php

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

$limit = 5;
$query_count    = "SELECT count(*) FROM port";
$result_count   = mysql_query($query_count);
$totalrows      = mysql_num_rows($result_count);

if(empty($page))
{
  $page = 1;
}

$limitvalue = $page * $limit - ($limit);
$query  = "SELECT * FROM port LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());

if(mysql_num_rows($result) == 0)
{
  echo("Nothing to Display!");
}
?>
And for pagination2
PHP:
<?php

if($page != 1)
{
  $pageprev = $page--;
  echo '<a href="callid_port.php&page='.$pageprev.'">PREV '.$limit.'</a> ';
}
else
{
  echo 'PREV '.$limit.' ');
}

$numofpages = $totalrows / $limit;

for($i = 1; $i <= $numofpages; $i++)
{
  if($i == $page)
  {
    echo $i.' ';
  }
  else
  {
    echo '<a href="callid_port.php?page='.$i.'">'.$i.'</a> ';
  }
}

if(($totalrows % $limit) != 0)
{
  if($i == $page)
  {
    echo $i.' ';
  }
  else
  {
    echo '<a href="callid_port.php?page='.$i.'">'.$i.'</a> ';
  }
}

if(($totalrows - ($limit * $page)) > 0)
{
  $pagenext = $page++;
  echo '<a href="callid_port.php?page='.$pagenext.'">NEXT '.$limit.'</a> ';
}
else
{
  echo 'NEXT '.$limit);
}

@mysql_free_result($result);

?>

Will take a closer look in a bit... Hope this helps tho :)


-Eric
 
0
•••
The links still aren't working :S
 
0
•••
Ok, try this. And this is all one file btw ;)

PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Portfolio</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

include('config.php');

$page = intval($_GET['p']);

if(!$page || $page == "")
{
  $page = 1;
}

$prev = $page - 1;
$next = $page + 1;
$ppage = 5;
$limit = ($page * $ppage) - $ppage;

$query = mysql_query("SELECT ID FROM port") or die("Error: ".mysql_error());
$num = mysql_num_rows($query);
$num_pages = ceil($num / $ppage);

$link = '';

if($page > 1)
{
  $link .= ' <a href="?p=1">First</a> <a href="?p='.$prev.'">Prev</a> ';
}

for($i = 1; $i <= $num_pages; $i++)
{
  if($page == $i)
  {
    $link .= ' <b>['.$i.']</b> ';
  }
  else
  {
    $link .= ' <a href="?p='.$i.'">'.$i.'</a> ';
  }
}

if($page < $num_pages)
{
  $link .= ' <a href="?p='.$next.'">Next</a> <a href="?p='.$num_pages.'">Last</a>';
}

?>
<table class='prod' cellpadding='3' border='3'>
<tr>
  <td colspan='4'><h3 align='center'>Sort Portfolio By: <a href='id.html'>All</a> | <a href='dsnrs.html'>Designer</a> | <a href='live.html'>Live Sites</a></h3></td>
</tr>
<tr>
  <td><h4 align='center'> Design Thumbnail </h4></td><td><h4 align='center'> Design Title </h4></td><td><h4 align='center'> Design Author </h4></td>
  <td><h4 align='center'> Design URL </h4></td>
</tr>
<?php

$query = mysql_query("SELECT * FROM port LIMIT ".$limit.", ".$ppage) or die("Error: ".mysql_error());

while($row = mysql_fetch_array($query))
{
  $id = $row["ID"];
  $dsnr = $row["dsnr"];
  $img = $row["img"];
  $live = $row["live"];
  $port_desc = $row["port_desc"];
  $href = $row["href"];
  $title = $row["title"];

  if(empty($row))
  {
    echo("<h1>Coming Soon!</h1>");
  }
  elseif($live==1)
  {
    $ahref = "<a href='" . $href . "' target='_blank'>" . $title . "</a> *Live Site!*" ;
  }
  else
  {
    $ahref = "Not Live";
  }
?>
<tr>
  <td class='td2'><a href='/images/<?php echo $img; ?>' target='_blank'><img width='90px' height='120px' src='/images/<?php echo $img; ?>' title='Click For Larget Image' border='0' /></a></td>
  <td class='td3'><p align='center'><?php echo $title; ?></p></td>
  <td class='td4'><?php echo $dsnr; ?></td>
  <td class='td5'><?php echo $ahref; ?></td>
</tr>
<tr>
  <td colspan='4'><blockquote> <p align='left'>Design Description:</p><? php echo $port_desc; ?></blockquote></td>
</tr>
<?php
}
?>
</table>
<br />
<?php echo $link; ?>

</body>
</html>
 
0
•••
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back