Jump to content

pagination help


Recommended Posts

how can i paginate this

require_once 'nav_bar.php';
if (isset($_GET['image_id']))
{
if ((int) $_GET['image_id'] > 0) 
{

$imageid = $_GET['image_id'];
$sql = "SELECT * FROM hayleyimages WHERE image_id=$imageid";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$imageprofname = $row['image_name'];
$imageprofcaption = $row['image_caption'];
$imageproflink = $row['image_link'];
if(mysql_num_rows($result) > 0)
{
?>
	<table id="portfolio_image">
<tr><th><?php echo "$imageprofname"; ?></th><td><?php echo '<a href="'.$row['image_link'].'" rel="lightbox" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="200px" /></a>'; ?></td><td width="200px"><?php echo 'Image ID :'.$row['image_id'].''; ?></td></tr><tr><td><?php echo ' '.$row['image_caption']. ' </a>'; ?></td></tr></table>
<?php
}
	if (mysql_num_rows($result) < 1) {
		 echo 'This ID does not exist in the database<br>';
		 echo "<a href=\"index.php\">Return to Image Page</a>";
		 exit();
	}
exit();
}
	else {
	 echo "Unknown Image ID! <br />";
	 echo "<a href=\"index.php\">Return to Image Page</a>";
	 exit();
	}
}
//No ID passed to page, display user list:
$query = "SELECT image_id, image_name, image_link, image_caption FROM `hayleyimages`";
$result = mysql_query($query) or die("Error:" . mysql_error());

if (mysql_num_rows($result) > 0) {
?>
<table class="welcome_port"><tr><td>Welcome this is my portfolio.</td></tr></table>
<table id="portfolio">
<?php
               $loop = 3;
		   $loop1 = 3;
	while($row=mysql_fetch_array($result)){ // Start looping table row

	if ($loop == 3) {
                        echo "<tr>";
                }
	$toecho1 .= '<td><a href="?image_id='.$row['image_id'].'">Details</a></td><td>    </td>';
	$toecho .= '<td><a href="'.$row['image_link'].'" rel="lightbox [main]" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="150px" /></a></td><td>    </td>';

                
                if ($loop == 3) 
			{
                        echo "</tr>";
                        $loop=0;
                }   


	}
               if (substr($toecho, -5) != "</tr>") {
                  $toecho .= "</tr>";
               }
               echo $toecho;
               echo $toecho1;
}

?>		
</table>
<?php
		if (mysql_num_rows($result) < 1) {
		echo "No Images To Display";
		}

mysql_close();
?>
</div>
</body>
</html>

 

this is the exact piece that needs paginating

 

<?php
               $loop = 3;
		   $loop1 = 3;
	while($row=mysql_fetch_array($result)){ // Start looping table row

	if ($loop == 3) {
                        echo "<tr>";
                }
	$toecho1 .= '<td><a href="?image_id='.$row['image_id'].'">Details</a></td><td>    </td>';
	$toecho .= '<td><a href="'.$row['image_link'].'" rel="lightbox [main]" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="150px" /></a></td><td>    </td>';

                
                if ($loop == 3) 
			{
                        echo "</tr>";
                        $loop=0;
                }   


	}
               if (substr($toecho, -5) != "</tr>") {
                  $toecho .= "</tr>";
               }
               echo $toecho;
               echo $toecho1;
}

?>	

 

i have tried pagination tutorials, but i can't ever get it to work

Link to comment
Share on other sites

Smarty <3

 

I've always hated pagination so when I found smarty and the plugin that was created specifically for pagination I jumped at it.  Plus smarty will help keep your logic seperate from your html this making programming much easier...

Link to comment
Share on other sites

i found this code,

<?php
$max = 2; //amount of articles per page. change to what to want

$p = $_GET['p'];

if(empty($p))

{

$p = 1;

}

$limits = ($p - 1) * $max; 

//view the news article!

if(isset($_GET['act']) && $_GET['act'] == "view")

{

$id = $_GET['id'];

$sql = mysql_query("SELECT * FROM hayleyimages WHERE image_id = '$id'");

while($r = mysql_fetch_array($sql))

{

$title = $r['image_name'];

$story = $r['image_caption'];

$author = $r['image_link'];

echo "<div><p>$title</p><p>$author</p><p>$story</p></div>";

}



}else{



//view all the news articles in rows

$sql = mysql_query("SELECT * FROM hayleyimages LIMIT ".$limits.",$max") or die(mysql_error());

//the total rows in the table

$totalres = mysql_result(mysql_query("SELECT COUNT(image_id) AS tot FROM hayleyimages"),0);	

//the total number of pages (calculated result), math stuff...

$totalpages = ceil($totalres / $max); 

//the table

echo "<table><tr><td>Title</td><td>Author</td></tr><tr>";

while($r = mysql_fetch_array($sql))

{

$id = $r['id'];

$title = $r['title'];

$author = $r['author'];

echo "<td><a href='news.php?act=view&id=$id'>$title</a></td><td>$author</td>";

}

//close up the table

echo "</tr></table>";

for($i = 1; $i <= $totalpages; $i++){ 

//this is the pagination link

echo "<a href='news.php?p=$i'>$i</a>|";

}

}
?>

 

now can some explain how to intergrate it into this code,

 

<?php
require_once 'nav_bar.php';
if (isset($_GET['image_id']))
{
if ((int) $_GET['image_id'] > 0) 
{

$imageid = $_GET['image_id'];
$sql = "SELECT * FROM hayleyimages WHERE image_id=$imageid";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$imageprofname = $row['image_name'];
$imageprofcaption = $row['image_caption'];
$imageproflink = $row['image_link'];
if(mysql_num_rows($result) > 0)
{
?>
<div id="prof_img">
	<table id="portfolio_image">
<tr><th><?php echo "$imageprofname"; ?></th></tr><tr><td><?php echo '<a href="'.$row['image_link'].'" rel="lightbox" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="200px" /></a>'; ?></td><td width="200px"><?php echo 'Image ID :'.$row['image_id'].''; ?></td></tr><tr><td><?php echo ' '.$row['image_caption']. ' </a>'; ?></td></tr><tr><td><a href="portfolio.php">Return To Gallery</a></td></tr></table></div>
<?php
}
	if (mysql_num_rows($result) < 1) {
		 echo 'This ID does not exist in the database<br>';
		 echo "<a href=\"index.php\">Return to Image Page</a>";
		 exit();
	}
exit();
}
	else {
	 echo "Unknown Image ID! <br />";
	 echo "<a href=\"index.php\">Return to Image Page</a>";
	 exit();
	}
}
//No ID passed to page, display user list:
$query = "SELECT image_id, image_name, image_link, image_caption FROM `hayleyimages`";
$result = mysql_query($query) or die("Error:" . mysql_error());

if (mysql_num_rows($result) > 0) {
?>
<table class="welcome_port"><tr><td>Welcome this is my portfolio.</td></tr></table>
<table id="portfolio">
<?php
               $loop = 3;
		   $loop1 = 3;
	while($row=mysql_fetch_array($result)){ // Start looping table row

	if ($loop == 3) {
                        echo "<tr>";
                }
	$toecho1 .= '<td><a href="?image_id='.$row['image_id'].'">Details</a></td><td>    </td>';
	$toecho .= '<td><a href="'.$row['image_link'].'" rel="lightbox [main]" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="150px" /></a></td><td>    </td>';

                
                if ($loop == 3) 
			{
                        echo "</tr>";
                        $loop=0;
                }   


	}
               if (substr($toecho, -5) != "</tr>") {
                  $toecho .= "</tr>";
               }
               echo $toecho;
               echo $toecho1;
}

?>		
</table>
<?php
		if (mysql_num_rows($result) < 1) {
		echo "No Images To Display";
		}

mysql_close();
?>
</div>
</body>
</html>

 

this bit in particular

<?php
               $loop = 3;
		   $loop1 = 3;
	while($row=mysql_fetch_array($result)){ // Start looping table row

	if ($loop == 3) {
                        echo "<tr>";
                }
	$toecho1 .= '<td><a href="?image_id='.$row['image_id'].'">Details</a></td><td>    </td>';
	$toecho .= '<td><a href="'.$row['image_link'].'" rel="lightbox [main]" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="150px" /></a></td><td>    </td>';

                
                if ($loop == 3) 
			{
                        echo "</tr>";
                        $loop=0;
                }   


	}
               if (substr($toecho, -5) != "</tr>") {
                  $toecho .= "</tr>";
               }
               echo $toecho;
               echo $toecho1;
}

?>		

Link to comment
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.