Fallen_angel Posted January 30, 2007 Share Posted January 30, 2007 Hi , I have a question that follows on from a topic I had here a bit under a month or so about creating a next and previous button based on database values I got that part sorted fine and it works well , however I want to tidy up the script by making it recognize the first and last tutorial so that it doesn't Display a back button for the first tutorial and so that it doesn't show a next button if there is no next rowis there a way that I can do this ?the topic I started a while ago can be found in this link [url=http://www.phpfreaks.com/forums/index.php/topic,122913.msg508473.html#msg508473]http://www.phpfreaks.com/forums/index.php/topic,122913.msg508473.html#msg508473[/url]I had a few lines of thought as to what i could do but am not sure eighter is the best way to do it First I was thinking of trying an if statement using isset however I have only had experiance doing that with submitted forms , and am not sure how to use it in this case the second idea I had was to do a count of the rows in a second statement and if the tutorial id matched that number use an if statement to not show the appropriate button the third idea i had will only work for the back option but at least it should do that ,and that was to have an if statement saying that if the tutorial id was equal to 1 then it doesn't show the back button Will any of these ideas work to achieve what i need ? or can anyone help with a solution that is better than any of the above idea's Quote Link to comment https://forums.phpfreaks.com/topic/36272-help-with-back-and-next-buttons-on-first-and-final-results/ Share on other sites More sharing options...
littlened Posted January 30, 2007 Share Posted January 30, 2007 I've not seen your code so I may be off the mark here, but...<?php if ($page > 1) echo "<img src='backbutton.gif;>"; ?>and for the forward button you should count the number of results.<?php if ($page < $maxresults) echo "<img src='forward.gif'>"; ?>this is how I do it[code]// Determine page and SQL limit$results_max = 10;if (!isset($_REQUEST['page'])) { $page = 1; } else { $page = $_REQUEST['page']; }$results_from = (($page * $results_max) - $results_max);// Count total number of results$results_total = 0;$sql = "SELECT * FROM DB";$sql_result = mysql_query($sql_count,$database) or die(mysql_error());while ($row = mysql_fetch_array($sql_result)) { $results_total++; } // Calculate the number of pages$results_pages = ceil($results_total / $results_max);// Get actual results$rc = 0;$sql = $SELECT * FROM DB";$sql_result = mysql_query($sql,$database) or die(mysql_error());while ($row = mysql_fetch_array($sql_result)) { $re_list[$rc]['DeptAir'] = get_airport_location($row['OfferDeptAir']); $re_list[$rc]['ArrAir'] = get_airport_location($row['OfferArrAir']); $re_list[$rc]['Hotel'] = get_hotel_desc($row['HotelID']); if ($row['HotelID'] == 0) $re_list[$rc]['Hotel'] = 'Accommodation on arrival or n/k'; $re_list[$rc]['Board'] = get_board_desc($row['OfferBB']); $re_list[$rc]['ID'] = $row['OfferID']; $re_list[$rc]['DeptDate'] = $row['OfferDeptDate']; list($year, $month, $day) = split('[/.-]', $re_list[$rc]['DeptDate']); $re_list[$rc]['DeptDate'] = $day."-".$month."-".$year; $re_list[$rc]['Company'] = $row['ClientCompany']; $re_list[$rc]['URL'] = $row['ProfileURL']; $re_list[$rc]['Sharing'] = $row['OfferSharing']; $re_list[$rc]['Class'] = $row['OfferClass']; $re_list[$rc]['TotalCost'] = $row['OfferTOD'] + $row['OfferFuel'] + $row['OfferTax'] + $row['OfferPrice'] + $row['OfferBFee']; $re_list[$rc]['Resort'] = $row['OfferResort']; $rc++; }[/code]then when it comes to displaying the page numbers.[code]<?php $p = 1; while ($p < $results_pages OR $p == $results_pages) { ?> [ <a href="offer_search_results.php?page=<?= $p.$page_link; ?>"><?= $p; ?></a> ] <?php $p++; } // END PAGE WHILE?>[/code]Though my solutions doesnt give you a back and forward button, but instead a list of pages. but the code should give you an idea. Quote Link to comment https://forums.phpfreaks.com/topic/36272-help-with-back-and-next-buttons-on-first-and-final-results/#findComment-172581 Share on other sites More sharing options...
Fallen_angel Posted January 30, 2007 Author Share Posted January 30, 2007 thankyou very much for your assistance i was able to achieve what i want to with your help :) Quote Link to comment https://forums.phpfreaks.com/topic/36272-help-with-back-and-next-buttons-on-first-and-final-results/#findComment-172603 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.