Mysql Query gets the right results from the database but wrong page count
<p>Hi I have a php query with pagination which retrieves the right, information from the database however it is getting the wrong page number count.  And almost looks like it is getting enough pages for the whole website and not just the results with the where clause.  However to me it all seems to be correct (though obviously something is wrong).</p>

<pre><code>$tableName="livetrack";     
$targetpage = "keywords.php";   
$limit = "20"; 

$query = "SELECT COUNT(*) as num FROM $tableName where member_id='$site_id' GROUP BY string";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];

$stages = 3;
$page = mysql_escape_string($_GET['page']);
if($page){
    $start = ($page - 1) * $limit; 
}else{
    $start = 0; 
    }   

// Get page data
$query1 = "SELECT string, COUNT(string)  FROM livetrack where member_id='$site_id' GROUP BY string ORDER BY COUNT(string) DESC LIMIT $start, $limit";
$result = mysql_query($query1);

// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;  
$next = $page + 1;                          
$lastpage = ceil($total_pages/$limit);      
$LastPagem1 = $lastpage - 1;

$paginate = '';
if($lastpage &gt; 1)
{   
</code></pre>

<p>Any suggestions would be greatly appreciated.</p>

<p>Thanks</p>
