deansaddigh Posted January 6, 2010 Share Posted January 6, 2010 Basically i need to give a page on my site at work new pagination, the script has already been written i just need to implement it, but i dont know how to . the page i need to implement it on already has pagination but it needs this new script for it. Heres the page the pagination needs to go on. <?php include('../lib/scripts/php/functions.php'); $page_title='Clients'; $page_id_top = 'clients'; $page_id = 'viewClients'; include('../lib/includes/header.php'); if (!empty($_GET['page'])) { $page = $_GET['page']; } else { $page = 1; } $limit = 20; unset($_SESSION['cottage']); ?> <div id="sub_nav"> <? include('subnav.php'); /* if (!empty($_POST['search'])) { $search = $_POST['search']; $clientSQL = "SELECT * FROM clients WHERE name like '%$search%' OR surname like '%$search%' OR email like '%$search%' OR address1 like '%$search%' OR town like '%$search%' OR postcode like '%$search%'OR county like '%$search%'"; $limit = 500; } else { $clientSQL = "SELECT * FROM clients WHERE name != '0' $cottageSQL $sortSQL"; } $clientsResults = $db->query($clientSQL); $total_clients = count ($clientsResults); $total_pages = ceil($total_clients / $limit); $set_limit = 1; $set_limit = $page * $limit - ($limit); $limitSQL = " LIMIT $set_limit,$limit"; $clientSQL = $clientSQL.$limitSQL; $clientsResults = $db->query($clientSQL);*/ /***********************************/ /*******NEW PAGING /***********************************/ //IF QUICK SEARCH IS SUBMITTED if (isset($_POST['search'])){ $searchKey = $_POST['search']; $search = "AND (p.propertyName LIKE '%$searchKey%' OR c.name LIKE '%$searchKey%' OR c.surname LIKE '%$searchKey%')"; } $clientSQL = dbExec("SELECT * FROM clients WHERE name != '0' $cottageSQL $sortSQL"); //*Bring Back \num $total = mysql_num_rows($clientSQL); //Set up items per page limit clause if(is_numeric($ipp)){ $from = ($page - 1) * $ipp; $to = $ipp; $limit = 'LIMIT '.$from.','.$to; $totalPages = ceil($total / $ipp); if($totalPages != 1){ $pageText = 'Pages'; if(($page + 1) <= $totalPages){ $next = ' <a href="'.$_SERVER['PHP_SELF'].'?cottage='.$f_cottage.'&location='.$f_location.'&sort='.$f_sort.'&page='.($page + 1).'&ipp='.$ipp.'" style="padding:0 0 0 10px;">Next </a>'; } if(($page) > 1){ $previous = ' <a href="'.$_SERVER['PHP_SELF'].'?cottage='.$f_cottage.'&location='.$f_location.'&sort='.$f_sort.'&page='.($page - 1).'&ipp='.$ipp.'" style="padding:0 0 0 10px;"> Previous</a>'; } }else{ $pageText = 'Page'; } }else{ $totalPages = '1'; $pageText = 'Page'; } $pagedBookings = dbExec("SELECT b.*, p.propertyName, u.admin_firstname, u.admin_surname, c.title,c.name,c.surname FROM bookings b, properties p, admin_users u, clients c WHERE b.property_id = p.id AND b.user_id = u.admin_id AND b.client_id = c.id AND b.archived ='' $search $locationSQL $cottageSQL $sortSQL $limit "); $paging = '<span>'.$page.' of '.$totalPages.' '.$pageText.'</span> '.$previous.' '.$next; /***********************************/ /*******End New Paging /***********************************/ ?> </div> <div id="content"> <div id="content_tab"> <!--START OF PAGE TABS--> <? include('tabs.php');?> <!--END OF PAGE TABS--> </div> <div id="content_contents"> <!--START OF PAGE CONTENT--> <? if (!empty ($clientsResults)) { foreach ($clientsResults as $clientsResults2) { ?> <div class="productItem"> <div class="productItemImage"><img src='images/client_icon.gif'></div> <div class="productItemDescription"> <table border='0'> <tr> <td width="130px">Name:</td> <td width="270px"><?=$clientsResults2{'title'}.' '.$clientsResults2{'name'}.' '.$clientsResults2{'surname'}?></td> </tr> <tr><td></td></tr> <tr> <td>Email address:</td> <td><?=$clientsResults2{'email'}?></td> </tr> <tr> <td>Telephone:</td> <td><?=$clientsResults2{'telephone'}?></td> </tr> <tr> <td>Last booking:</td> <?php $sql="SELECT arrival_date, departure_date FROM bookings WHERE client_id = ".$clientsResults2{'id'}." ORDER BY id DESC LIMIT 1"; $dateSQL = mysql_query($sql)or die($sql.mysql_error()); $dateResults = mysql_fetch_array($dateSQL); ?> <td><?= "Check-in: " .$dateResults['arrival_date']. "<br />Checkout: " . $dateResults['departure_date'];?></td> </tr> </table> <BR clear='all'> <table border='0' width='600'> <tr> <td> <div class="buttonLeft" style='float:left;margin-left:450px;'><a href="clients/addClients.php?id=<?=$clientsResults2{'id'}?>">View/Edit Details</a></div> </td> </table> </div> </div> <BR clear='all' /> <div class="orangeDivider" style='margin-top:10px; margin-left:100px;'></div> <? } } else { echo 'No results found!'; } //------------------------------ //PREV //------------------------------ if (!empty($clientsResults)) { $prev_page = $page - 1; if($prev_page >= 1) { echo("<a href=clients/index.php?page=$prev_page><b>Previous</b></a>"); } else { echo("<b><font color='#999999'>Previous</b></font>"); } } //------------------------------ //PAGES //------------------------------ for($a = 1; $a <= $total_pages; $a++) { if($a == $page) { echo("<b> $a</b> | "); //no link } else { echo(" <a href=clients/index.php?page=$a> $a </a> | "); } } //------------------------------ //PAGES //------------------------------ if (!empty($clientsResults)) { $next_page = $page + 1; if($next_page <= $total_pages) { echo("<a href=clients/index.php?page=$next_page><b>Next</b></a>"); } else { echo("<b><font color='#999999'>Next</b></font>"); } } ?> <!--END OF PAGE CONTENTS--> </div> </div> <?php include('../lib/includes/footer.php'); ?> Heres the code for the script. //IF QUICK SEARCH IS SUBMITTED if (isset($_POST['search'])){ $searchKey = $_POST['search']; $search = "AND (p.propertyName LIKE '%$searchKey%' OR c.name LIKE '%$searchKey%' OR c.surname LIKE '%$searchKey%')"; } $totalBookings = dbExec("SELECT b.id FROM bookings b, properties p, admin_users u, clients c WHERE b.property_id = p.id AND b.user_id = u.admin_id AND b.client_id = c.id AND b.archived ='' $search $locationSQL $cottageSQL $sortSQL"); $total = mysql_num_rows($totalBookings); //Set up items per page limit clause if(is_numeric($ipp)){ $from = ($page - 1) * $ipp; $to = $ipp; $limit = 'LIMIT '.$from.','.$to; $totalPages = ceil($total / $ipp); if($totalPages != 1){ $pageText = 'Pages'; if(($page + 1) <= $totalPages){ $next = ' <a href="'.$_SERVER['PHP_SELF'].'?cottage='.$f_cottage.'&location='.$f_location.'&sort='.$f_sort.'&page='.($page + 1).'&ipp='.$ipp.'" style="padding:0 0 0 10px;">Next </a>'; } if(($page) > 1){ $previous = ' <a href="'.$_SERVER['PHP_SELF'].'?cottage='.$f_cottage.'&location='.$f_location.'&sort='.$f_sort.'&page='.($page - 1).'&ipp='.$ipp.'" style="padding:0 0 0 10px;"> Previous</a>'; } }else{ $pageText = 'Page'; } }else{ $totalPages = '1'; $pageText = 'Page'; } $pagedBookings = dbExec("SELECT b.*, p.propertyName, u.admin_firstname, u.admin_surname, c.title,c.name,c.surname FROM bookings b, properties p, admin_users u, clients c WHERE b.property_id = p.id AND b.user_id = u.admin_id AND b.client_id = c.id AND b.archived ='' $search $locationSQL $cottageSQL $sortSQL $limit "); $paging = '<span>'.$page.' of '.$totalPages.' '.$pageText.'</span> '.$previous.' '.$next; Link to comment https://forums.phpfreaks.com/topic/187430-help-needed-with-pagination/ Share on other sites More sharing options...
deansaddigh Posted January 6, 2010 Author Share Posted January 6, 2010 Its ok i have figured it out Link to comment https://forums.phpfreaks.com/topic/187430-help-needed-with-pagination/#findComment-989750 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.