AdRock Posted March 6, 2010 Share Posted March 6, 2010 I have been tearing my hair out all night with this problem and I can't see any logical explanation for it. I have a pagination function that works perfectly normal unless I use a mysql full text search on it. I have just tested it commenting out the SQL with the full text search and it works but as soon as i put the full text SQL back in it doesn't work. I have viewed the source and the function is being called but it's not displaying the links. It just creates and empty <ul> Here is the code in question <?php require_once('php/database/MySQL.php'); require_once('php/database/connection.php'); function pagination_one($total_pages,$page){ // Global variable passed between the pages global $webpage; // Maximum number of links per page. If exceeded, google style pagination is generated $max_links = 10; $h=1; if($page>$max_links){ $h=(($h+$page)-$max_links); } if($page>=1){ $max_links = $max_links+($page-1); } if($max_links>$total_pages){ $max_links=$total_pages+1; } echo '<div class="page_numbers"> <ul>'; if($page>"1"){ echo '<li class="current"><a href="'.$webpage.'.php?pagenum=1">First</a></li> <li class="current"><a href="'.$webpage.'.php?pagenum='.($page-1).'">Prev</a></li> '; } if($total_pages!=1){ for ($i=$h;$i<$max_links;$i++){ if($i==$page){ echo '<li><a class="current">'.$i.'</a></li>'; } else{ echo '<li><a href="'.$webpage.'.php?pagenum='.$i.'">'.$i.'</a> </li>'; } } } if(($page >="1")&&($page!=$total_pages)){ echo '<li class="current"><a href="'.$webpage.'.php?pagenum='.($page+1).'">Next</a></li> <li class="current"><a href="'.$webpage.'.php?pagenum='.$total_pages.'">Last</a></li> '; } echo '</ul> </div>'; } //if (!empty($_POST['keywords'])) $_SESSION['keywords'] = $_POST['keywords']; //$keywords = strtolower($_SESSION['keywords']); //$uckeywords = ucwords($_SESSION['keywords']); $keywords = "festival"; $path = "test"; $webpage = basename($path); $db = & new MySQL($host,$dbUser,$dbPass,$dbName); if (isset($keywords)) { /*$count = "SELECT count(*), MATCH(eventname, location, postcode, additional) AGAINST('$keywords*' IN BOOLEAN MODE) as score FROM festivals WHERE MATCH(eventname, location, postcode, additional) AGAINST('$keywords*' IN BOOLEAN MODE) group by festivalid"; $sql = "sELECT eventname, location, postcode, additional, MATCH(eventname, location, postcode, additional) AGAINST('$keywords*' IN BOOLEAN MODE) as score FROM festivals WHERE MATCH(eventname, location, postcode, additional) AGAINST('$keywords*' IN BOOLEAN MODE)";*/ $count = "SELECT count(*) FROM festivals"; $sql = "sELECT eventname, location, postcode, additional FROM festivals"; } // Perform a query getting back a MySQLResult object $res = $db->query($count); $result = $db->query($sql); //get the number of rows in datatbase $getresult = $result->size(); $numrows = $res->fetchrow(); if(isset($_GET['pagenum'])?$page = $_GET['pagenum']:$page = 1); $entries_per_page = 1; $total_pages = ceil($numrows[0]/$entries_per_page); $offset = (($page * $entries_per_page) - $entries_per_page); $sql = "sELECT eventname, location, postcode, additional, MATCH(eventname, location, postcode, additional) AGAINST('$keywords*' IN BOOLEAN MODE) as score FROM festivals WHERE MATCH(eventname, location, postcode, additional) AGAINST('$keywords*' IN BOOLEAN MODE) order by score desc LIMIT $offset,$entries_per_page"; // Perform a query getting back a MySQLResult object $result = $db->query($sql); $err = $result->size(); if($err == 0) { echo ("No matches met your criteria."); } else { while ($row = $result->fetch()) { $eventname = html_entity_decode(ucwords($row['eventname'])); $location = html_entity_decode($row['location']); $additional = html_entity_decode($row['additional']); $placeholders = array($keywords, $uckeywords); $vals = array("<span class='searchbold'>$keywords</span>", "<span class='searchbold'>$uckeywords</span>"); $link = str_replace($placeholders, $vals, $eventname); $loc = str_replace($placeholders, $vals, $location); $add = str_replace($placeholders, $vals, $additional); echo "<p class='searchlink'><a href='festival.php?festival=".strtolower(str_replace(' ','-',$eventname))."'>".$link."</a>"; echo " - ".$loc."</p>"; echo "<p class='searchinfo'>".$add."</p>"; echo "<p class='searchurl'>http://www.folktaskforce.com/festival.php?festival=".strtolower(str_replace(' ','-',$eventname))."</p>"; } //or after the results pagination_one($total_pages,$page); } echo "</div>"; ?> Link to comment https://forums.phpfreaks.com/topic/194303-pagination-doesnt-work-with-mysql-full-text-search/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.