dachshund Posted February 11, 2010 Share Posted February 11, 2010 hi, i have a website which contains features, interviews, reviews and a blog. all the articles pretty much run down in a blog format, but you can also select a specific section like 'interviews' in the nav bar. i would like to put next and previous buttons at the bottom of each article, which would take you to the next of that type. for example, if you're on an interview, next would take you to the next interview (which would be the next lower id where section == 'interview' in this case) and never a feature or review etc. in the address bar i have s=interview (or whatever the section is). so i can do WHERE `section` like $s, for the next button, but what can i add to this to find the next (lower or higher) id? i hope that all makes sense. thanks for any help in advance. Link to comment https://forums.phpfreaks.com/topic/191772-next-and-previous/ Share on other sites More sharing options...
jskywalker Posted February 11, 2010 Share Posted February 11, 2010 You can add 'action=next', or 'action=previous' to the address bar, But that is not gong to solve the problem, because you have to write some code which act upon the value of this 'action' Link to comment https://forums.phpfreaks.com/topic/191772-next-and-previous/#findComment-1010763 Share on other sites More sharing options...
dachshund Posted February 11, 2010 Author Share Posted February 11, 2010 no no. i just want to make basic next and previous buttons, all i need to know is how you can tell it to find the id number before the current one. they're not all in order so i can't do $rows['id'] - 1 thanks though. Link to comment https://forums.phpfreaks.com/topic/191772-next-and-previous/#findComment-1010767 Share on other sites More sharing options...
sader Posted February 11, 2010 Share Posted February 11, 2010 there is stuff like LIMIT start_from, num_of_rows_to_take in MySQL Example: SELECT * FROM topics LIMIT 0, 20; will return first 20 entires from table SELECT * FROM topics LIMIT 80, 20; returns 20 entries from table starting from 80th so if you would pass some $_GET var via url lets say $_GET['page'] setup your sql like $sql = "SELECT * FROM topics LIMIT ".($_GET['page'] * 20).", 20 ORDER BY date DESC"; //will take 20 entries from table and sort them from newest to oldest Link to comment https://forums.phpfreaks.com/topic/191772-next-and-previous/#findComment-1010772 Share on other sites More sharing options...
dachshund Posted February 11, 2010 Author Share Posted February 11, 2010 soryr i don't think i explained very well. all i want to do is have a next button and a previous button, like on a blog or facebook gallery or anything else. where when you click next it goes to the next article. Link to comment https://forums.phpfreaks.com/topic/191772-next-and-previous/#findComment-1010800 Share on other sites More sharing options...
sader Posted February 11, 2010 Share Posted February 11, 2010 then maybe u can do it like so lets say u have url which leads tu exact article number similar to article.php?id=10 //connection $AID = $_GET['id']; if(is_numeric($AID) && $AID > 0) { //now the query if($_GET['step'] == 'next') { $sql = "SELECT * FROM articles WHERE id>$AID ORDER BY id ASC LIMIT 1"; } else if($_GET['step'] == 'prev') { $sql = "SELECT * FROM articles WHERE id<$AID ORDER BY id DESC LIMIT 1"; } else { //if non of the above select exact article $sql = "SELECT * FROM articles WHERE id=$AID LIMIT 1"; } //execute query $result = mysql_query($sql); //your ouput here //finaly <<prev next>> buttons echo "<a href='article.php?id=$AID&step=prev'>prev</a>"; echo "<a href='article.php?id=$AID&step=next'>next</a>"; } theoreticly it shoud work try out and say if it's working Link to comment https://forums.phpfreaks.com/topic/191772-next-and-previous/#findComment-1010809 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.