suttercain Posted April 13, 2007 Share Posted April 13, 2007 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 Link to comment https://forums.phpfreaks.com/topic/46942-previous-next-did-search-but-couldnt-find-my-problem/ Share on other sites More sharing options...
Barand Posted April 14, 2007 Share Posted April 14, 2007 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 Link to comment https://forums.phpfreaks.com/topic/46942-previous-next-did-search-but-couldnt-find-my-problem/#findComment-228921 Share on other sites More sharing options...
suttercain Posted April 14, 2007 Author Share Posted April 14, 2007 Worked like a charm. Thanks Barand. Have a nice weekend! Link to comment https://forums.phpfreaks.com/topic/46942-previous-next-did-search-but-couldnt-find-my-problem/#findComment-229028 Share on other sites More sharing options...
suttercain Posted April 14, 2007 Author Share Posted April 14, 2007 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 Link to comment https://forums.phpfreaks.com/topic/46942-previous-next-did-search-but-couldnt-find-my-problem/#findComment-229036 Share on other sites More sharing options...
Barand Posted April 14, 2007 Share Posted April 14, 2007 You could change the issue number to INT instead of a character field Link to comment https://forums.phpfreaks.com/topic/46942-previous-next-did-search-but-couldnt-find-my-problem/#findComment-229086 Share on other sites More sharing options...
suttercain Posted April 14, 2007 Author Share Posted April 14, 2007 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 Link to comment https://forums.phpfreaks.com/topic/46942-previous-next-did-search-but-couldnt-find-my-problem/#findComment-229240 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.