everlifefree Posted March 5, 2008 Share Posted March 5, 2008 ok i'm looking to make a next button for my site that goes up looks at the id of the page your on and then when you click the next button it takes you to the next one in line it the database. and it can't just go 1, 2, 3, 4, ect. because there are missing variable from deletions some it'd need to be able to read like this 1, 2, 5, 6, 7, 12, ect. (you get the point of just serveal missing numbers between. Quote Link to comment https://forums.phpfreaks.com/topic/94444-next-button/ Share on other sites More sharing options...
discomatt Posted March 5, 2008 Share Posted March 5, 2008 Why not: $r = mysql_query('SELECT `id` FROM `table`'); while ($arr = mysql_fetch_assoc($r)) echo '<a href="page.php?id=' . $arr['id'] . '">' . $arr['id'] . '</a> '; Quote Link to comment https://forums.phpfreaks.com/topic/94444-next-button/#findComment-483676 Share on other sites More sharing options...
haku Posted March 5, 2008 Share Posted March 5, 2008 or: "SELECT id FROM table WHERE id > current_page_id ORDER BY id ASC LIMIT 1" Quote Link to comment https://forums.phpfreaks.com/topic/94444-next-button/#findComment-483698 Share on other sites More sharing options...
everlifefree Posted March 5, 2008 Author Share Posted March 5, 2008 k but what would be the url for the next button? Quote Link to comment https://forums.phpfreaks.com/topic/94444-next-button/#findComment-484106 Share on other sites More sharing options...
everlifefree Posted March 5, 2008 Author Share Posted March 5, 2008 URL anyone? Quote Link to comment https://forums.phpfreaks.com/topic/94444-next-button/#findComment-484362 Share on other sites More sharing options...
haku Posted March 5, 2008 Share Posted March 5, 2008 Add one to the current page ID. You are going to have to set the currentp age ID first though - use a $_GET variable. Quote Link to comment https://forums.phpfreaks.com/topic/94444-next-button/#findComment-484410 Share on other sites More sharing options...
everlifefree Posted March 5, 2008 Author Share Posted March 5, 2008 so my original url is like: http://mysite.com?L=index.gallery&id=57 but to call the next page what'd the url be? Quote Link to comment https://forums.phpfreaks.com/topic/94444-next-button/#findComment-484424 Share on other sites More sharing options...
sasa Posted March 6, 2008 Share Posted March 6, 2008 use SELECT * FROM TABLES WHERE id>=$id AND ... LIMIT 2 in 1st featch you have curent data, and in 2nd is next id Quote Link to comment https://forums.phpfreaks.com/topic/94444-next-button/#findComment-484437 Share on other sites More sharing options...
teng84 Posted March 6, 2008 Share Posted March 6, 2008 use SELECT * FROM TABLES WHERE id>=$id AND ... LIMIT 2 in 1st featch you have curent data, and in 2nd is next id why dont you just do it this way so it will only fetch one record? SELECT * FROM TABLES WHERE id>$id AND ... LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/94444-next-button/#findComment-484441 Share on other sites More sharing options...
everlifefree Posted March 6, 2008 Author Share Posted March 6, 2008 I get that side of things but I need the exact URL to fetch the next page?? Quote Link to comment https://forums.phpfreaks.com/topic/94444-next-button/#findComment-484597 Share on other sites More sharing options...
haku Posted March 6, 2008 Share Posted March 6, 2008 It should be the same URL as the page you are on, just using the next ID number. Quote Link to comment https://forums.phpfreaks.com/topic/94444-next-button/#findComment-484614 Share on other sites More sharing options...
everlifefree Posted March 6, 2008 Author Share Posted March 6, 2008 Here's the code I attempted but I get all it puts in {ezine.id2} is the number 1 and that isn't right! Can anyone tell me where I went wrong?? if (isset($_GET["id"])) $row2 = myF(myQ(" SELECT * FROM `[x]gallery` WHERE 'id' > '{$_GET["id"]}' AND `processed` = '1' ORDER BY 'id' ASC LIMIT 1 ")); $tpl -> AssignArray(array( "ezine.id2" => $row2["id"], )); Quote Link to comment https://forums.phpfreaks.com/topic/94444-next-button/#findComment-485338 Share on other sites More sharing options...
everlifefree Posted March 7, 2008 Author Share Posted March 7, 2008 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/94444-next-button/#findComment-485850 Share on other sites More sharing options...
everlifefree Posted March 7, 2008 Author Share Posted March 7, 2008 Anyone know where I went wrong? Quote Link to comment https://forums.phpfreaks.com/topic/94444-next-button/#findComment-486350 Share on other sites More sharing options...
haku Posted March 8, 2008 Share Posted March 8, 2008 I'm about to go on a trip with the wife so I only have about one minute to post. I dont know what is wrong with your current code, but use this: if(isset($_GET['page_id'])) { $query = "SELECT page_id FROM pages WHERE page_id > " . $_GET['page_id'] . " ORDER BY page_id ASC LIMIT 1"; } else { $query = "SELECT page_id FROM pages WHERE page_id > 1 ORDER BY page_id ASC LIMIT 1"; } // Do your mysql query here echo "<a href=\"page_name?page_id=" . $page_id_taken_from_database . "\">NEXT PAGE</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/94444-next-button/#findComment-486603 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.