Want to add pagination in my code
<p>There are two tables in my code both are dynamic the data is coming in each table according to a auction and classified but i m unable to put the pagination in my code.</p>

<p>Pagination numbers are showing but not data and I want pagination to come after second table and if the per page limit is 5 then 5 records should be shown in both tables.</p>

<p>Here is my code:</p>

<pre><code>&lt;?php

include 'includes/common.inc.php';

include $main_path . 'language/' . $language . '/categories.inc.php';

include $include_path . 'dates.inc.php';

include 'header.php';

echo '&lt;div class="tableContent2"&gt;&lt;div class="titTablelink"&gt;Search Result&lt;/div&gt;&lt;/div&gt;';

define('MAX_REC_PER_PAGE', 5);
  $rs = mysql_query("SELECT COUNT(*) FROM auctions") or die("Count query error!");
  list($total) = mysql_fetch_row($rs);


  $total_pages = ceil($total / MAX_REC_PER_PAGE);


  $page = intval(@$_GET["page"]); 
  if (0 == $page){
  $page = 1;
  }  
  $start = MAX_REC_PER_PAGE * ($page - 1);
  $max = MAX_REC_PER_PAGE;

if($_REQUEST['q'])
{
    $q=$_REQUEST['q'];
    $mainquery="select * from  auctions where title like '%$q%' order by starts desc $start,$max";
}


$catvise=$_POST['catvise'];

switch($_POST['match'])
    {
        case 'exact':
            $keyword=" title=".$q." and category=".$catvise;
            break;

        case 'any':
            $keyword=" title like '%$q%' and category=".$catvise;
            break;
    }

        if(isset($_POST['fsearch']))        
        {               
            $mainquery="select * from auctions where".$keyword;         
        }


$qry1=mysql_query($mainquery);

?&gt;

&lt;!--Filter search--&gt;
&lt;form action="" method="post"&gt;
&lt;table width="971" height="41" border="0" align="center" cellspacing="1"&gt; 
    &lt;tr&gt;&lt;td colspan="4"&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr bgcolor="#B0B0B0"&gt;
        &lt;td align="center"&gt;&lt;input name="q" type="text"&gt;&lt;/td&gt;

        &lt;td align="center"&gt;&lt;select name="match" &gt;
                &lt;option value="exact"&gt;Match exactly&lt;/option&gt;
                &lt;option value="any" selected&gt;Has any words&lt;/option&gt;
            &lt;/select&gt;&lt;/td&gt;

        &lt;td align="center"&gt;&lt;select name="catvise"&gt;
        &lt;option value=""&gt;In any category&lt;/option&gt;

        &lt;?php

                $cat_name_qry=mysql_query("select * from categories order by parent_id");
                while($cat_name_data=mysql_fetch_array($cat_name_qry))
                {                   
                    if($cat_name_data['level']=='1')
                    {                       
                        $pn=mysql_query("select cat_name from categories where cat_id=".$cat_name_data['parent_id']."");
                        $parent_name=mysql_fetch_array($pn);

                        $parent_name['cat_name']=substr($parent_name['cat_name'],0,4);

                        echo "&lt;option value='".$cat_name_data['cat_id']."'&gt;" .$parent_name['cat_name']." - ".$cat_name_data['cat_name']. "&lt;/option&gt;";                       
                    }
                }
        ?&gt;
            &lt;/select&gt;&lt;/td&gt;

        &lt;td align="center"&gt;&lt;input name="fsearch" type="submit" value="Search"&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;&lt;td colspan="4"&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td colspan="4"&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td colspan="4"&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/form&gt;

&lt;!--ends here --&gt;


&lt;!--Auction records start--&gt;
&lt;?php
if(mysql_num_rows($qry1)&gt;0)
{
    ?&gt;

&lt;table width="971" height="41" border='0' align='center' cellspacing="1"&gt;
    &lt;tr align="left" class="titTablelink"&gt;
        &lt;th width="704"&gt;Auction&lt;/th&gt;&lt;th width="150"&gt;Category&lt;/th&gt;&lt;th width="111" align="right"&gt;Bid&lt;/th&gt;
    &lt;/tr&gt;

&lt;?php
while($data=mysql_fetch_array($qry1))
{
    if($data['auction_type']==1)
        {

            $qry2=mysql_query("select c.cat_name,a.auction_type from categories c,auctions a where c.cat_id=a.category and a.id=".$data['id']." group by cat_name");
            $data1=mysql_fetch_array($qry2);
            $cat_name=$data1['cat_name'];

            echo "&lt;tr valign='top'&gt;
                    &lt;td&gt;&lt;a href='item.php?id=".$data['id']."'&gt;".$data['title']."&lt;/a&gt;&lt;/td&gt;
                    &lt;td&gt;".$cat_name."&lt;/td&gt;
                    &lt;td align='right'&gt;".$data['minimum_bid']."&lt;/td&gt;";

        }
}
echo '&lt;/tr&gt;&lt;tr&gt;&lt;td colspan="3"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan="3"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan="3"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;';



?&gt;
&lt;!--Auction records end--&gt;

&lt;!--Classified records start--&gt;
&lt;table width="971" height="41" border='0' align='center' cellspacing="1"&gt;
&lt;tr align="left" class="titTablelink"&gt;
            &lt;th width="704"&gt;Classifieds&lt;/th&gt;&lt;th width="150"&gt;Category&lt;/th&gt;&lt;th width="111" align="right"&gt;Asking&lt;/th&gt;
    &lt;/tr&gt;
   &lt;?php
   $qry3=mysql_query($mainquery);
   if(mysql_num_rows($qry1)&gt;0)
    {
        while($data2=mysql_fetch_array($qry3))
        {
            if($data2['auction_type']=='')
                {
                    $qry4=mysql_query("select c.cat_name,a.auction_type from categories c,auctions a where c.cat_id=a.category and a.id=".$data2['id']." group by cat_name");
                    $data3=mysql_fetch_array($qry4);
                    $cat_name=$data3['cat_name'];
                    echo "&lt;tr valign='top'&gt;
                            &lt;td&gt;&lt;a href='item1.php?id=".$data2['id']."'&gt;".$data2['title']."&lt;/a&gt;&lt;/td&gt;
                            &lt;td&gt;".$cat_name."&lt;/td&gt;
                            &lt;td align='right'&gt;".$data2['minimum_bid']."&lt;/td&gt;";
                }

        }
        echo "&lt;/tr&gt;&lt;/table&gt;";
    }
}
        else
            {
                echo '&lt;div class="padding" align="center "&gt;&lt;b&gt;&lt;font size="30"&gt;No Record Found.&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;';               
                echo "&lt;/tr&gt;&lt;/table&gt;";
            }       
             echo '&lt;table border="0" cellpadding="5" align="center"&gt;
  &lt;tr&gt;
  &lt;td&gt;Goto Page:&lt;/td&gt;';

  for ($i = 1; $i &lt;= $total_pages; $i++) {
  $txt = $i;
  if ($page != $i)
  $txt = "&lt;a href=\"" . $_SERVER["PHP_SELF"] . "?page=$i\"&gt;".$txt."&lt;/a&gt;";

  echo '&lt;td align="center"&gt;'.$txt.'&lt;/td&gt;';
  }

  echo '&lt;/tr&gt;
  &lt;/table&gt;';
?&gt;
&lt;!--Classified records end--&gt;

&lt;/body&gt;
&lt;/html&gt;
&lt;?php include 'footer.php';?&gt;
</code></pre>
