Jump to content

Pagination woes


Ltj_bukem

Recommended Posts

 

Hi,

 

I am working on a simple pagination script, similar to the one on this sites tutorial section. I have a search

form which displays the results on one page, if there are over 17 results a 2nd page is created, 34 results a third page & so on.

The links between the pages work fine, the problem I have is that no matter what page I am on only the first pages results are displayed.

I think it may be a problem with the actual links that create the new pages.

 

Here's the code

 

?php




$search= $_POST['search'];



if (isset($_POST['go']))

       {





mysql_connect("***", "****", "*****") or die("Error connecting to MySQL: ".mysql_error());

mysql_select_db("******") or die("Error selecting database: ".mysql_error());


//$search = strtoupper($search);
$search = strip_tags($search);
$search= trim ($search);



$query = "SELECT * FROM download1 WHERE dance LIKE '%$search%' OR
name LIKE '%$search%'";


$result = mysql_query ($query);

$total = mysql_num_rows($result);
if ($search == "")
{

echo "<p>You forgot to enter a search term.";


}

if($total > 0)

{


echo "Searching for $search produced $total results";
       echo "<br></br>";

}

while (list($id, $name, $temp, $dance) = mysql_fetch_array($result))    {

//while(list($id, $name, $temp, $dance) = mysql_fetch_array($result))

{
   // echo "<a href=\"$temp\">$name</a></br>";

  echo "<br><a href=\"download3.php?id=$id\">$name</a></br>";
  $searchvar = 1;
}
    }
echo "</ul>";

if  ((!$search == "") && ($searchvar != 1))
{echo "<p>No matches found, please refine your search.";}


}


?>

 

Heres the page for the next & prev links

 


if ( $pageNum> 1)
{
        $page = $pageNum- 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</font></a> ";

$first = " <a href=\"$self?page=1\">[First Page]</font></a> ";
}
else
{
$prev  = '<font size="2" face="verdana">[Prev]</font>';     
$first = '<font size="2" face="verdana">[First Page]</font>';
}



if ( $page < $total_pages  )
{
          $page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\">[Next]</a> ";

$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";

}
else
{
$next = '<font size="2" face="verdana"> [Next] </font>';      // we're on the last page, don't enable 'next' link
$last = '<font size="2" face="verdana"> [Last Page] </font>'; // nor 'last page' link
}
       
if ($pageNum == $total_pages)
{
  $next  = '<font size="2" face="verdana"> [Lext] </font>';
          $last = '<font size="2" face="verdana"> [Last Page] </font>';   
}
echo $first.$prev."<font size='2' face='verdana'> Showing page </font><strong><font color='blue'>$pageNum</font></strong><font size='2' face='verdana'> of </font><strong><font color='blue'>$total_pages</font></strong><font size='2' face='verdana'> pages </font></strong></font>" . $next . $last;
?>
[/Code]

 

Any help would be cool, I'm almost there.

 

Link to comment
https://forums.phpfreaks.com/topic/77189-pagination-woes/
Share on other sites

Maybe not the best code, but it works and maybe it will give you an idea of what you need to do.

 

# Get Paging data
$getpgid = ($_GET['page']);
if (!isset($getpgid)) { $getpgid = "1";  }
if  (!is_numeric($getpgid)) { $getpgid = "1"; }
$clean2 = $getpgid . "0";
$clean1 = ($clean2 - 10);

$getlistn = mysql_query("SELECT * FROM `events` ");
if (!$getlistn) { die ("Unable to list events"); }

# Print Page listings
$cntx = mysql_num_rows($getlistn); // count the rows
$divb = ceil(intval($cntx)/10)*10; //  round total results to a number divisible by 10
$howmany = ceil($divb / 10); //number of times 10 goes into total rows

Print "[ Pages: ";
for ($ix = 1; $ix <= $howmany; $ix++)
{
   if ($ix != $howmany)
  {
  echo "<a href=www.example.com&page=$ix>$ix</a> - ";
  } 
else {
echo "<a href=www.example.com&page=$ix>$ix</a>";
     }
}
print " ]";

$getlist = mysql_query("SELECT * FROM `events` LIMIT $clean1 , $clean2");
if (!$getlist) { die ("Unable to list projects"); }

Link to comment
https://forums.phpfreaks.com/topic/77189-pagination-woes/#findComment-390817
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.