...

View Full Version : Pagination



jamesk
02-16-2010, 01:27 PM
Hello,

I have an image hosting script with an admin backend - but all images just show on one page - i can't find a pagination script to get it to work! Also, when a new file is uploaded, it appears at the bottom of the page - can someone work out how to get it to appear at the top?

Could someone tell me how to do this please?


<title>planetK Moderation</title><font face='verdana'> <?
session_start();
if(!session_is_registered(myusername)){
header("location:admin.php");
}
?>
<?
include("config.php");
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
echo "<center><br><font face=verdana size=4><b>picK Image Moderation</b></font></center>";
echo "<p align=center><font size=1 face=verdana><a href=admin_success.php>Moderation</a>| <a href=admin_success.php?p=u>Ban List</a> | <a href=admin_logout.php>Logout</a></font></p><br>";

$con = mysql_connect($data_server, $data_user, $data_pw)
or die("<font color= red>Couldn't connect to Database. Try again.</font>");
mysql_select_db("db");
if($_GET['p'] == ""){
$result = mysql_query("SELECT * FROM image_table ")
or die(mysql_error());
print "<font face='verdana' size='1'><center><table border=1px #000000 solid><tr><td>File Preview</td><td>Delete</td><td>Ban</td></tr>";
while($row = mysql_fetch_array( $result )) {
$filename = $row['image'];
$extension = getExtension($filename);
$extension = strtolower($extension);
if($row['image'] == ""){
} else {
if($extension == "jpeg" || $extension == "jpg" || $extension == "png" || $extension == "gif" || $extension == "bmp") {
//Echo Link
echo "<tr><td><a href='";
echo $row['image'];
echo "' border='0'>";
echo "<img src='";
echo $row['image'];
echo "' width='70px' height='70px' border='0'></a></td><td>";
} else {
//IF NOT AN IMAGE
//CLICK HERE LINK
echo "<font face=verdana size=small>";
echo "<tr><td><a href='";
echo $row['image'];
echo "'>Click here</a></td><td>";
}
//DELTE
echo "<a href='deleted.php?name=";
echo $row['image'];
echo "'>Delete File</a></td><td>";
//BAN
echo "<a href='banban.php?ip=";
echo $row['ip'];
echo "'>Ban</a>";
echo "<br />";
echo $row['ip'];
echo "</font>";
echo "</td></tr>";
}
}
}
if($_GET['p'] == "u"){
mysql_connect($data_server, $data_user, $data_pw)
or die("Couldn't connect to Database. Try again.");
mysql_select_db("db");
$result = mysql_query("SELECT * FROM banip ")
or die(mysql_error());
print "<center><table border='1'>";
while($row = mysql_fetch_array( $result )) {
print "<tr><td>";
print $row['IP'];
print "</td><td>";
print "<a href='unbanban.php?ip=";
print $row['IP'];
print "'>Unban IP</a></td></tr>";
}
}
?></font>

I'm still learning :P

Cheers,
James

JAY6390
02-16-2010, 02:16 PM
http://www.jaygilford.com/php/completely-customisable-php-pagination-class/
Instructions are on the site on how to integrate it with your code

Any problems post back

Jay

JAY6390
02-16-2010, 02:59 PM
OK download the class into the same directory as this script (naming it paginate.class.php), then change your script to the following and hopefully it will work

<title>planetK Moderation</title><font face='verdana'> <?
require 'paginate.class.php';
$page = isset($_GET['page']) ? $_GET['page'] : 1;
session_start();
if (!session_is_registered(myusername)) {
header("location:admin.php");
}

include ("config.php");
function getExtension($str)
{
$i = strrpos($str, ".");
if (!$i) {
return "";
}
$l = strlen($str) - $i;
$ext = substr($str, $i + 1, $l);
return $ext;
}
echo "<center><br><font face=verdana size=4><b>picK Image Moderation</b></font></center>";
echo "<p align=center><font size=1 face=verdana><a href=admin_success.php>Moderation</a>| <a href=admin_success.php?p=u>Ban List</a> | <a href=admin_logout.php>Logout</a></font></p><br>";

$con = mysql_connect($data_server, $data_user, $data_pw) or die("<font color= red>Couldn't connect to Database. Try again.</font>");
mysql_select_db("db");
if ($_GET['p'] == "") {
// Query to run
$query = "SELECT * FROM image_table ";

// Load paginator
$paginator = new pagination($page, $query);

// Number of results on each page
$paginator->results_per_page = 10;

// Number of pages to show around current page number in links
$paginator->padding(2);

// Link prefix before page number
$paginator->link_prefix = '?page=';

// Paginate the results
$page_links = $paginator->paginate();

// Echo out the page links
echo $page_links;

print "<font face='verdana' size='1'><center><table border=1px #000000 solid><tr><td>File Preview</td><td>Delete</td><td>Ban</td></tr>";
while ($row = mysql_fetch_array($paginator->resource())) {
$filename = $row['image'];
$extension = getExtension($filename);
$extension = strtolower($extension);
if ($row['image'] == "") {
} else {
if ($extension == "jpeg" || $extension == "jpg" || $extension == "png" || $extension ==
"gif" || $extension == "bmp") {
//Echo Link
echo "<tr><td><a href='";
echo $row['image'];
echo "' border='0'>";
echo "<img src='";
echo $row['image'];
echo "' width='70px' height='70px' border='0'></a></td><td>";
} else {
//IF NOT AN IMAGE
//CLICK HERE LINK
echo "<font face=verdana size=small>";
echo "<tr><td><a href='";
echo $row['image'];
echo "'>Click here</a></td><td>";
}
//DELTE
echo "<a href='deleted.php?name=";
echo $row['image'];
echo "'>Delete File</a></td><td>";
//BAN
echo "<a href='banban.php?ip=";
echo $row['ip'];
echo "'>Ban</a>";
echo "<br />";
echo $row['ip'];
echo "</font>";
echo "</td></tr>";
}
}
}
if ($_GET['p'] == "u") {
mysql_connect($data_server, $data_user, $data_pw) or die("Couldn't connect to Database. Try again.");
mysql_select_db("db");
$result = mysql_query("SELECT * FROM banip ") or die(mysql_error());
print "<center><table border='1'>";
while ($row = mysql_fetch_array($result)) {
print "<tr><td>";
print $row['IP'];
print "</td><td>";
print "<a href='unbanban.php?ip=";
print $row['IP'];
print "'>Unban IP</a></td></tr>";
}
}
?></font>Note your code is very poor (ie written in tables and <font> tags). You should consider upgrading it to a higher standard tbh.

jamesk
02-16-2010, 03:56 PM
I will be changing the page to css and div tags - i hate tables - but it'll do for now...

As I said, I'm just happy this script is actually working - uploading images lol

Edit; This is what I get:

Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/j/k/jkealey/public_html/pick/paginate.class.php on line 17

JAY6390
02-16-2010, 04:01 PM
Not sure why you get that. The pagination script has no errors. Did you modify it in any way? Make sure you download the pagination script instead of copy pasting it off the site to be absolutely sure. it should show a download box when you click the download button

jamesk
02-16-2010, 04:03 PM
I did, I downloaded it straight off and put it in the same directory as the other page. I then copied and pasted the script from above and replaced the page.

Looks like the error is with your script... :S

James

JAY6390
02-16-2010, 04:07 PM
can you create a temp ftp user and pass and PM me the details of your site so that I can see what it might be. both scripts have no errors according to my php parser

JAY6390
02-16-2010, 04:36 PM
As I expected my pagination class is fine, as was the code I gave you to run. The problem was your servers version of PHP (Version 4.4.1). The pagination script is for version 5 and above of PHP. PHP 4 was deprecated as of December 31st 2007 so its assumed all hosting now has PHP5 (although since you are on a free host you can't really do anything about it). I've changed the script so that all the public and private keywords are removed, and added a pagination function to the class since __construct won't work. It now works (I changed the results per page to 1 to demonstrate since you only have 3 items to paginate)

jamesk
02-16-2010, 05:09 PM
Oh right, Cheers :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum