I am having trouble paging mysql results that use the full text.
If i change my query to not use full text, the paging works fine but when i change it back to use full text it doesn’t show any paging links. It calls the function to create the links but just creates an empy unordered list.
Anyone know why this is happening?
<?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?pagen=1">First</a></li>
<li class="current"><a href="'.$webpage.'.php?page='.($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?page='.$i.'">'.$i.'</a> </li>';
}
}
}
if(($page >="1")&&($page!=$total_pages)){
echo '<li class="current"><a href="'.$webpage.'.php?page='.($page+1).'">Next</a></li>
<li class="current"><a href="'.$webpage.'.php?page='.$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['page'])?$page = $_GET['page']:$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()) {
//All my results are printed here
}
//or after the results
pagination_one($total_pages,$page);
}
echo "</div>";
?>