Jump to content

Previous & Next - Did Search but couldn't find my problem.


suttercain

Recommended Posts

Hi everyone,

 

I will try to explain this as best I can and post the code.

 

I have a site which has comics books. Each comic is in the MySQL database and seprated as such:

 

COLUMN 1         

TITLE

Superman

Action Comics

Supergirl

etc.

 

COLUMN 2

ISSUE_NUMBER

351

722

22

 

I want to be able to have it so when the user looks st let's say Superman #500 and click next it takes them to Superman #501, previous would have taken them to #499.

 

Now this is the problem,

There have been numerous issues, of let's say, Supergirl #2 because there are different volumes 1, 2, 3, etc.

 

Luckily I do have a third column with the volume.

 

How would I get it so if the user is viewing Supergirl #3 Volume 1, when they click Next they are taken to Supergirl #4, Volume 1?

 

This is currently how I fetch the data based on the comic_id column:

require ('get_connected.php');

if (isset($_GET['id'])) {
    $sql = "SELECT * FROM comics WHERE comic_id = '" . mysql_real_escape_string($_GET['id']) . "'";
    if ($result = mysql_query($sql)) {
      if (mysql_num_rows($result)) {
        $row = mysql_fetch_assoc($result);
      }
    }
  }

Is it possible to set it up to do the previous and next the way I need it to run?

Thank for the suggestions and help.

SC

 

Lets say they're on Superman issue #500

 

Next

SELECT * FROM comics 
WHERE title='Superman' AND issue > 500
ORDER BY issue
LIMIT 1

 

Previous

SELECT * FROM comics 
WHERE title='Superman' AND issue < 500
ORDER BY issue DESC
LIMIT 1

 

Sorry I wrote too soon. I got the previous to and next to work... for the most part. The issue I am running into is this. Let's say I am viewing issue number 74 and click next I go to 75, cool. But then I click next again and I am at 750. Is there a type of natsort() for the MySQL database? Instead of the ORDER BY? I am going to try looking it up now, but I think I looked before and couldn't find anything.

 

Thanks again Barand and to everyone else who pitches in around here. Tonight I am donating.

 

SC

It is an INT field. I got it working, but it's weird, once it gets to record 4100 or above the link goes dead. and it does this http://www.domain.com.com/view_comics.php?id= instead of http://www.domain.com.com/view_comics.php?id=4100

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.