Jump to content

Recommended Posts

After 3-4 cups of coffee, 2 headaches, and a major brain cramp, I finally have gotten a skeleton, workable system for pagination, and a thourough understanding of the basic concept behind it, so I can replicate it later, or customize it more when I have all this set in.  For now I am against a wall, Ihave encountered 2 things with my script, and no matter how hard I think at this point, I cannot figure these 2 things out.
THe system it self works perfectly, it is set up right, and for it to keep working, I can just change the number to 50, and it will use 50 results, as well as I can put it on every case switch and it will all work properly, the thing here is though, it works.  However there are 2 issues I can't figure out.
1. If they try to go previous, for instance if they go next 1 time, then previous 2 times, it passes there current script, adn starts showing a blank page, it keeps lessening that number, and never stops, so each time you hit previous, it goes to another blank page. 
2. The same for next, you can keep going to next for ever.  How can I factor in when to make it now show next, and not show previous, I don't want those showing up if there is nothing there, any advice on how I can fix this.
[code]<?php
session_start();
?>
<!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>
<?php
include './includes/meta.inc.php'; // includes meta tags, stylesheet, and javascript inclusion
?>
</head>
<body>
<div id="wrap">
<?php
include './includes/header.inc.php'; // inserts header, logo, and everything up there
?>
    <br style="clear: both;" />

<?php
include './includes/leftnav.inc.php'; // inserts left navigation
?>

    <div id="content">

        <div class="overall">
<h3>Postings</h3>
<?php
// connect to database
mysql_connect("#######", "#####", "######");
mysql_select_db("joyel");
// get together the critical variables, and clean them up.
$postset = mysql_real_escape_string($_GET['ps']);
$school = mysql_real_escape_string($_GET['s']);
$category = mysql_real_escape_string($_GET['c']);
$subcategory = mysql_real_escape_string($_GET['sc']);
$limit = 2;
$limit = mysql_real_escape_string($limit);
if ($_GET['rownumberprev']) {
$rownumber = mysql_real_escape_string($_GET['rownumberprev']);
}elseif ($_GET['rownumbernext']) {
$rownumber = mysql_real_escape_string($_GET['rownumbernext']);
}else {
$rownumber = 0;
}

// go through databases.  Easier to keep up with, let's start with database number 1
switch ($postset) {
// Work with database postset1
case "postset1":
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school' ORDER BY dateentered
LIMIT $rownumber, $limit;";
$query = mysql_query($select);
$num_rows = mysql_num_rows($query);
echo "<hr />";
while ($row = mysql_fetch_array($query)) {
echo "<br />";
echo "<a href=\"view.php\" title\"View Post\">{$row[itemtitle]}-{$row[price]}-
{$row[dateentered]}</a>";
echo "<br />";
}
echo "<hr />";
echo "<br />";
$rownumberprev = $rownumber - 2;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumberprev={$rownumberprev}\">Previous Page</a>";
echo "<br />";
$rownumbernext = $rownumber + 2;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumbernext={$rownumbernext}\">Next Page</a>";

break;
// work with database postset2
case "postset2":
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school';";
$query = mysql_query($select);
while ($row = mysql_fetch_array($query)) {

}
break;
// work with database postset3
case "postset3":
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school';";
$query = mysql_query($select);
while ($row = mysql_fetch_array($query)) {

}
break;
// work with database postset4
case "postset4":
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school';";
$query = mysql_query($select);
while ($row = mysql_fetch_array($query)) {

}
break;
// work with database postset5
case "postset5":
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school';";
$query = mysql_query($select);
while ($row = mysql_fetch_array($query)) {

}
break;
// work with database postset6
case "postset6":
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school';";
$query = mysql_query($select);
while ($row = mysql_fetch_array($query)) {

}
break;
// work with database postset7
case "postset7":
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school';";
$query = mysql_query($select);
while ($row = mysql_fetch_array($query)) {

}
break;
// work with database postset8
case "postset8":
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school';";
$query = mysql_query($select);
while ($row = mysql_fetch_array($query)) {

}
break;
}
?>

        </div>

    </div>
<?php
include './includes/banner.inc.php'; // includes the banner, randomly selected from a database
?>

<?php
include './includes/footer.inc.php'; // includes the page footer, bottom navigation copyright
?>
</div>
</body>
</html>[/code]
By the way I asked this after awhile of fighting with the different greater than less than, and equal to or less than, and equal to or less that, trying to use a variety of combinations of numrows, and record number, to try and make previous disappear, when there are none before, and vice versa, but nothing worked.
shit, that never happened before.  I have been dealing with a lot later, 2 days ago, I spent 11 hours of doing the hardest programming I ever had before straight.  Then I spent 4 hours the next day(yesterday, tuesday), finishing that up, then about 8 hours of even harder programming, followed up by pagination today(which was the hardest), so because of that, I guess I am getting a little burnt out.  Now I am stuck on this and it's not working, I changed that by the way, but now I looked at the variables, when the first page comes up, $rownumber is first set to 0
when I go
if ($rownumber == 0) {
// echo the previous link
}
then it still displays the previous link??
[code]
<?php
if ($rownumber != 0) {
   $rownumberprev = $rownumber - 2;
   echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumberprev={$rownumberprev}\">Previous Page</a>";
echo "<br />";
}
?>
[/code]
That seemed to have fixed up the previous link properly, it seems to be working, but nothign seems to be working for the next link.
The previous link was showing no matter what, and even at the beginning, if they hit it, it changed to -2, so it kept going, I fixed that with what I showed earlier, now for some reason the next link's not working.  I need it to disappear, I even created a test query to get the total number of rows from the database, and still can't figure out anything to make the next link disappear, I just want to make it to where when it get's to the final page of results, then it makes the next link disappear.  But nothing at this point seems to be working.
I have it set going back 2 and forward 2
I am increasing that to 50, that is how many records it's going to jump

For instance if my limit is 50, the starting row is 0, the first record set is 0-50, after that 50-100 then 100-150 well you get the point.  But you see what I mean.  I need to get the next link changed, hten I am changing all of those to 50.
Try...

[code]<?php
if ($rownumber <= $num_rows -2){
  $rownumbernext = $rownumber + 2;
  echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc={$subcategory}&rownumbernext={$rownumbernext}\">Next Page</a>";
}
?>[/code]

If this doesn't work, do you have it working somewhere I can see it?

Regards
Huggie
Someone told me something vaguely similar, as a favor can you explani that to me, so I understand the point.  I want advice from everyone here, this is NOT asking for help this time, this is asking for a script analysis I guess you could call it.  I have finished the whole thing, it has previous and next buttons, I have to go back and do my queries( like what they are displaying) because the data will be different for each one.  I just don't want to get to the point where I go ahead and say it's finished, and then 2 months from now they are complaining about something to do with the site, and it ends up being something with teh  pagination system that didn't go right.  If you can just look over everything, tell me if everything is right, if you don't see any problems then I am declaring it done.  It works right for both previous and next pages, and everything seems to work properly.??  Is there anything i Missed before I declare it done.

[code]<?php
session_start();
?>
<!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>
<?php
include './includes/meta.inc.php'; // includes meta tags, stylesheet, and javascript inclusion
?>
</head>
<body>
<div id="wrap">
<?php
include './includes/header.inc.php'; // inserts header, logo, and everything up there
?>
    <br style="clear: both;" />

<?php
include './includes/leftnav.inc.php'; // inserts left navigation
?>

    <div id="content">

        <div class="overall">
<h3>Postings</h3>
<?php
// connect to database
mysql_connect("mysql185.secureserver.net", "####", "#####");
mysql_select_db("joyel");
// get together the critical variables, and clean them up.
$postset = mysql_real_escape_string($_GET['ps']);
$school = mysql_real_escape_string($_GET['s']);
$category = mysql_real_escape_string($_GET['c']);
$subcategory = mysql_real_escape_string($_GET['sc']);
$limit = 50;
$limit = mysql_real_escape_string($limit);
if ($_GET['rownumberprev']) {
$rownumber = mysql_real_escape_string($_GET['rownumberprev']);
}elseif ($_GET['rownumbernext']) {
$rownumber = mysql_real_escape_string($_GET['rownumbernext']);
}else {
$rownumber = 0;
}

// go through databases.  Easier to keep up with, let's start with database number 1
switch ($postset) {
// Work with database postset1
case "postset1":
// test query for total row numbers
$testselect = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school';";
$testquery = mysql_query($testselect);
$total_rows = mysql_num_rows($testquery);
// query db
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school' ORDER BY dateentered
LIMIT $rownumber, $limit;";
$query = mysql_query($select);
$num_rows = mysql_num_rows($query);
echo "<hr />";
while ($row = mysql_fetch_array($query)) {
echo "<br />";
echo "<a href=\"view.php\" title\"View Post\">{$row[itemtitle]}-{$row[price]}-
{$row[dateentered]}</a>";
echo "<br />";
$temp = true;
}
if ($temp != true) {
echo "We apologize but there were no results";
}
echo "<hr />";
if ($rownumber != 0) {
$rownumberprev = $rownumber - 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumberprev={$rownumberprev}\">Previous Page</a>";
echo "<br />";
}
if ($rownumber <= ($total_rows - 50)) {
$rownumbernext = $rownumber + 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumbernext={$rownumbernext}\">Next Page</a>";
}
break;
// work with database postset2
case "postset2":
// test query for total row numbers
$testselect = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school';";
$testquery = mysql_query($testselect);
$total_rows = mysql_num_rows($testquery);
// query db
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school' ORDER BY dateentered
LIMIT $rownumber, $limit;";
$query = mysql_query($select);
$num_rows = mysql_num_rows($query);
echo "<hr />";
while ($row = mysql_fetch_array($query)) {
echo "<br />";
echo "<a href=\"view.php\" title\"View Post\">{$row[itemtitle]}-{$row[price]}-
{$row[dateentered]}</a>";
echo "<br />";
$temp = true;
}
if ($temp != true) {
echo "We apologize but there were no results";
}
echo "<hr />";
if ($rownumber != 0) {
$rownumberprev = $rownumber - 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumberprev={$rownumberprev}\">Previous Page</a>";
echo "<br />";
}
if ($rownumber <= ($total_rows - 50)) {
$rownumbernext = $rownumber + 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumbernext={$rownumbernext}\">Next Page</a>";
}
break;
// work with database postset3
case "postset3":
// test query for total row numbers
$testselect = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school';";
$testquery = mysql_query($testselect);
$total_rows = mysql_num_rows($testquery);
// query db
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school' ORDER BY dateentered
LIMIT $rownumber, $limit;";
$query = mysql_query($select);
$num_rows = mysql_num_rows($query);
echo "<hr />";
while ($row = mysql_fetch_array($query)) {
echo "<br />";
echo "<a href=\"view.php\" title\"View Post\">{$row[itemtitle]}-{$row[price]}-
{$row[dateentered]}</a>";
echo "<br />";
$temp = true;
}
if ($temp != true) {
echo "We apologize but there were no results";
}
echo "<hr />";
if ($rownumber != 0) {
$rownumberprev = $rownumber - 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumberprev={$rownumberprev}\">Previous Page</a>";
echo "<br />";
}
if ($rownumber <= ($total_rows - 50)) {
$rownumbernext = $rownumber + 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumbernext={$rownumbernext}\">Next Page</a>";
}
break;
// work with database postset4
case "postset4":
// test query for total row numbers
$testselect = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school';";
$testquery = mysql_query($testselect);
$total_rows = mysql_num_rows($testquery);
// query db
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school' ORDER BY dateentered
LIMIT $rownumber, $limit;";
$query = mysql_query($select);
$num_rows = mysql_num_rows($query);
echo "<hr />";
while ($row = mysql_fetch_array($query)) {
echo "<br />";
echo "<a href=\"view.php\" title\"View Post\">{$row[itemtitle]}-{$row[price]}-
{$row[dateentered]}</a>";
echo "<br />";
$temp = true;
}
if ($temp != true) {
echo "We apologize but there were no results";
}
echo "<hr />";
if ($rownumber != 0) {
$rownumberprev = $rownumber - 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumberprev={$rownumberprev}\">Previous Page</a>";
echo "<br />";
}
if ($rownumber <= ($total_rows - 50)) {
$rownumbernext = $rownumber + 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumbernext={$rownumbernext}\">Next Page</a>";
}
break;
// work with database postset5
case "postset5":
// test query for total row numbers
$testselect = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school';";
$testquery = mysql_query($testselect);
$total_rows = mysql_num_rows($testquery);
// query db
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school' ORDER BY dateentered
LIMIT $rownumber, $limit;";
$query = mysql_query($select);
$num_rows = mysql_num_rows($query);
echo "<hr />";
while ($row = mysql_fetch_array($query)) {
echo "<br />";
echo "<a href=\"view.php\" title\"View Post\">{$row[itemtitle]}-{$row[price]}-
{$row[dateentered]}</a>";
echo "<br />";
$temp = true;
}
if ($temp != true) {
echo "We apologize but there were no results";
}
echo "<hr />";
if ($rownumber != 0) {
$rownumberprev = $rownumber - 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumberprev={$rownumberprev}\">Previous Page</a>";
echo "<br />";
}
if ($rownumber <= ($total_rows - 50)) {
$rownumbernext = $rownumber + 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumbernext={$rownumbernext}\">Next Page</a>";
}
break;
// work with database postset6
case "postset6":
// test query for total row numbers
$testselect = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school';";
$testquery = mysql_query($testselect);
$total_rows = mysql_num_rows($testquery);
// query db
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school' ORDER BY dateentered
LIMIT $rownumber, $limit;";
$query = mysql_query($select);
$num_rows = mysql_num_rows($query);
echo "<hr />";
while ($row = mysql_fetch_array($query)) {
echo "<br />";
echo "<a href=\"view.php\" title\"View Post\">{$row[itemtitle]}-{$row[price]}-
{$row[dateentered]}</a>";
echo "<br />";
$temp = true;
}
if ($temp != true) {
echo "We apologize but there were no results";
}
echo "<hr />";
if ($rownumber != 0) {
$rownumberprev = $rownumber - 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumberprev={$rownumberprev}\">Previous Page</a>";
echo "<br />";
}
if ($rownumber <= ($total_rows - 50)) {
$rownumbernext = $rownumber + 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumbernext={$rownumbernext}\">Next Page</a>";
}
break;
// work with database postset7
case "postset7":
// test query for total row numbers
$testselect = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school';";
$testquery = mysql_query($testselect);
$total_rows = mysql_num_rows($testquery);
// query db
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school' ORDER BY dateentered
LIMIT $rownumber, $limit;";
$query = mysql_query($select);
$num_rows = mysql_num_rows($query);
echo "<hr />";
while ($row = mysql_fetch_array($query)) {
echo "<br />";
echo "<a href=\"view.php\" title\"View Post\">{$row[itemtitle]}-{$row[price]}-
{$row[dateentered]}</a>";
echo "<br />";
$temp = true;
}
if ($temp != true) {
echo "We apologize but there were no results";
}
echo "<hr />";
if ($rownumber != 0) {
$rownumberprev = $rownumber - 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumberprev={$rownumberprev}\">Previous Page</a>";
echo "<br />";
}
if ($rownumber <= ($total_rows - 50)) {
$rownumbernext = $rownumber + 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumbernext={$rownumbernext}\">Next Page</a>";
}
break;
// work with database postset8
case "postset8":
// test query for total row numbers
$testselect = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school';";
$testquery = mysql_query($testselect);
$total_rows = mysql_num_rows($testquery);
// query db
$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND
subcategoryname = '$subcategory' AND schoolname = '$school' ORDER BY dateentered
LIMIT $rownumber, $limit;";
$query = mysql_query($select);
$num_rows = mysql_num_rows($query);
echo "<hr />";
while ($row = mysql_fetch_array($query)) {
echo "<br />";
echo "<a href=\"view.php\" title\"View Post\">{$row[itemtitle]}-{$row[price]}-
{$row[dateentered]}</a>";
echo "<br />";
$temp = true;
}
if ($temp != true) {
echo "We apologize but there were no results";
}
echo "<hr />";
if ($rownumber != 0) {
$rownumberprev = $rownumber - 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumberprev={$rownumberprev}\">Previous Page</a>";
echo "<br />";
}
if ($rownumber <= ($total_rows - 50)) {
$rownumbernext = $rownumber + 50;
echo "<a href=\"display.php?ps={$postset}&s={$school}&c={$category}&sc=
{$subcategory}&rownumbernext={$rownumbernext}\">Next Page</a>";
}
break;
}
?>

        </div>

    </div>
<?php
include './includes/banner.inc.php'; // includes the banner, randomly selected from a database
?>

<?php
include './includes/footer.inc.php'; // includes the page footer, bottom navigation copyright
?>
</div>
</body>
</html>[/code]
I know, that is something I always do.  I do that for get, post, session, and sometimes even variables I create, to avoid any possibilty.  There may not be a possibility, but incase if there is, then it's there, incase
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.