here's what i already have, whenever i click a specified letter like for example 'A' it must print out and count how many countries starting with that letter. The problem is whenever the count is greater than the specified limit, when i clicked to page 2, it shows also countries starting with letter B.. pls help.
<html>
<body>
<link rel="stylesheet" type="text/css" href="ddcolortabs.css">
<?php
include('dbconn1.php');\
if(!$dbconn)
{
echo "Error: ".mysql_error();
exit;
}
$tbl_name="cc_country";
$adjacents = 2;
$query = "SELECT COUNT(countryname) AS num FROM ".$tbl_name." WHERE countryname LIKE '".strval(strtoupper($_REQUEST['s']))."%'";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
$targetpage = $_SERVER['PHP_SELF'];
$limit = 15;
if(isset($_GET['page']))
{
$page = $_GET['page'];
}
if($page)
{
$start = ($page - 1) * $limit;
}
else
{
$start = 0;
}
$sql = "SELECT * FROM ".$tbl_name." WHERE countryname LIKE '".strval(strtoupper($_REQUEST['s']))."%' ORDER BY countryname ASC LIMIT $start, $limit";
$result = mysql_query($sql);
if ($page == 0) $page = 1;
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$lpm1 = $lastpage - 1;
$pagination = "";
if($lastpage > 1)
{
if ($page > 1)
{
$pagination.= "<a href=\"$targetpage?page=$prev\" class=\"link\">«</a> ";
}
else
{
$pagination.= "<span class=\"disabled\">«</span>";
}
if ($lastpage < 7 + ($adjacents * 2))
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
{
$pagination.= "<span class=\"current\">$counter</span>";
}
else
{
$pagination.= "<a href=\"$targetpage?page=$counter\" class=\"link\">$counter</a>";
}
}
}
elseif($lastpage > 5 + ($adjacents * 2))
{
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
{
$pagination.= "<span class=\"current\">$counter</span>";
}
else
{
$pagination.= "<a href=\"$targetpage?page=$counter\" class=\"link\">$counter</a>";
}
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\" class=\"link\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\" class=\"link\">$lastpage</a>";
}
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?page=1\" class=\"link\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\" class=\"link\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
{
$pagination.= "<span class=\"current\">$counter</span>";
}
else
{
$pagination.= "<a href=\"$targetpage?page=$counter\" class=\"link\">$counter</a>";
}
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\" class=\"link\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\" class=\"link\">$lastpage</a>";
}
else
{
$pagination.= "<a href=\"$targetpage?page=1\" class=\"link\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\" class=\"link\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
{
$pagination.= "<span class=\"current\">$counter</span>";
}
else
{
$pagination.= "<a href=\"$targetpage?page=$counter\" class=\"link\">$counter</a>";
}
}
}
}
if ($page < $counter - 1)
{
$pagination.= " <a href=\"$targetpage?page=$next\" class=\"link\">»</a>";
}
else
{
$pagination.= "<span class=\"disabled\">»</span>";
}
}
?>
<tr>
<td colspan="2" align="center" style="font-size:10px; text-decoration:underline;">
Page <?php echo $page; ?> of <?php echo $lastpage; ?>
</td>
</tr>
<tr>
<td colspan="2" height="2">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<?php echo $pagination; ?>
</td>
</tr>
<tr>
<td colspan="2" height="3">
</td>
</tr>
<br />
<br />
<tr>
<?php
echo ("<br>");
while($row = mysql_fetch_array($result))
{
echo ("<div class='test'><a href='sourceLink1.php?mod=2&tbl=".$tbl_name."&c=".$row['countryname']."' target='showframe'>".$row['countryname']."</a></div>");
}
?>
</tr>
</body>
</html>
Thank you in advance guys. :)