i have a pagination code but that one is for single page,becaz in that url was changed. so if i add 2 or 3 pagination in single page that url was not changed.

someone help me

Recommended Answers

All 4 Replies

Member Avatar for diafol

What are you asking for? This doesn't make much sense.
It would help if you posted your code and explained clearly what happens and what you'd like to happen.

Please post your question clearly. Are you talking about more than one record listing with respective pagination for them ?

my code.i need a pagination for rel="country1" and rel="country2" in same page. here i added pagination code but that is not working properly.it works only one pagination coding in one page.

<div class="leftcontainer">

<ul id="countrytabs" class="shadetabs">
<li selected=""><a class="selected" href="index.php?city=$city&search" rel="country1" title="Search Categories">Search Categories</a></li>
<li><a class="" href="index.php?city=$city&article&page=1" rel="country2" title="Article Categories">Article Categories</a></li>
<li><a class="" href="#" rel="country3" title="Best Deals">Best Deals</a></li>
<li><a class="" href="#" rel="country4" title="Why Us?" style="margin-right:0px;">Why Us?</a></li>
</ul>

<div style="padding:0 5px 3px;">         
            <!-- Contents Tab1 Begins here -->
<div style="display: none;" id="country1" class="other_tabs" valign="top">

             <?php
    /*
        Place code to connect to your DB here.
    */
    include('db.php');  // include your code to connect to DB.

    $tbl_name="catagorykeywords";       //your table name
    // How many adjacent pages should be shown on each side?
    $adjacents = 3;

    /* 
       First get total number of rows in data table. 
       If you have a WHERE clause in your query, make sure you mirror it here.
    */

    $query = "select count(DISTINCT MainCatagory,id,name,path,size) as num from catagorykeywords ";
    $total_pages = mysql_fetch_array(mysql_query($query));
    $total_pages = $total_pages[num];

    /* Setup vars for query. */
    $targetpage = "index.php?city=$city&search";    //your file name  (the name of this file)
    $limit = 10;                                //how many items to show per page
    $page = $_GET['page'];
    if($page) 
        $start = ($page - 1) * $limit;          //first item to display on this page
    else
        $start = 0;                             //if no page var is given, set start to 0

    /* Get data. */

    $sql = mysql_query("select DISTINCT MainCatagory,id,name,path,size from catagorykeywords  ORDER BY id  DESC LIMIT $start,$limit");
    //$result = mysql_query($sql);

    /* Setup page vars for display. */
    if ($page == 0) $page = 1;                  //if no page var is given, default to 1.
    $prev = $page - 1;                          //previous page is page - 1
    $next = $page + 1;                          //next page is page + 1
    $lastpage = ceil($total_pages/$limit);      //lastpage is = total pages / items per page, rounded up.
    $lpm1 = $lastpage - 1;                      //last page minus 1

    /* 
        Now we apply our rules and draw the pagination object. 
        We're actually saving the code to a variable in case we want to draw it more than once.
    */
    $pagination = "";
    if($lastpage > 1)
    {   
        $pagination .= "<div class=\"pagination\">";
        //previous button
        if ($page > 1) 
            $pagination.= "<a href=\"$targetpage&page=$prev\"> previous</a>";
        else
            $pagination.= "<span class=\"disabled\"> previous</span>";    

        //pages 
        if ($lastpage < 7 + ($adjacents * 2))    //not enough pages to bother breaking it up
        {   
            for ($counter = 1; $counter <= $lastpage; $counter++)
            {
                if ($counter == $page)
                    $pagination.= "<span class=\"current\">$counter</span>";
                else
                    $pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";                   
            }
        }
        elseif($lastpage > 5 + ($adjacents * 2))    //enough pages to hide some
        {
            //close to beginning; only hide later pages
            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\">$counter</a>";                   
                }
                $pagination.= "...";
                $pagination.= "<a href=\"$targetpage&page=$lpm1\">$lpm1</a>";
                $pagination.= "<a href=\"$targetpage&page=$lastpage\">$lastpage</a>";     
            }
            //in middle; hide some front and some back
            elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
            {
                $pagination.= "<a href=\"$targetpage&page=1\">1</a>";
                $pagination.= "<a href=\"$targetpage&page=2\">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\">$counter</a>";                   
                }
                $pagination.= "...";
                $pagination.= "<a href=\"$targetpage&page=$lpm1\">$lpm1</a>";
                $pagination.= "<a href=\"$targetpage&page=$lastpage\">$lastpage</a>";     
            }
            //close to end; only hide early pages
            else
            {
                $pagination.= "<a href=\"$targetpage&page=1\">1</a>";
                $pagination.= "<a href=\"$targetpage&page=2\">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\">$counter</a>";                   
                }
            }
        }

        //next button
        if ($page < $counter - 1) 
            $pagination.= "<a href=\"$targetpage&page=$next\">next </a>";
        else
            $pagination.= "<span class=\"disabled\">next </span>";
        $pagination.= "</div>\n";        
    }
?>                
                    <?php
                        /*include("db.php");

                        $sql = mysql_query("select DISTINCT Maincatagory from spa where City='$city'");

                           while($v = mysql_fetch_array($sql))
                            {
                              $maincatagory=$v['Maincatagory'];
                              echo'<div class="subcatagoriesleft"><h2>'.$v['Maincatagory'].'</h2>';
                                 $sql1 = mysql_query("select DISTINCT Catagory from spa where Maincatagory='$maincatagory'");
                                  echo'<ul>';
                                      while($v1= mysql_fetch_array($sql1))
                                      {
                                      echo'<li><a href="searchbycat.php?catagory='.$v1['Catagory'].'">'.$v1['Catagory'].',</a></li>';
                                      }
                                  echo'</ul>';
                              echo'</div>';
                             // echo'<hr/>';

                             }*/

                             include("db.php");


                           while($v = mysql_fetch_array($sql))
                            {
                              $maincatagory=$v['MainCatagory'];
                              //$subcategory = $v['Subcatagory'];
                              $catid = $v['id'];
                              $name = $v['name'];
                              $path = $v['path'];
                              $size = $v['size']; ///backend/upimg/caticon/'.$v['name'].'
                              date_default_timezone_set('UTC');
                                $today = date("Y-m-d");
                                $dt = $today.'_'.time();

                                $enc = urlencode($maincatagory);


                              if($name)
                              echo '<div class="subcatagoriesleft"><img src="/backend/'.$v['path'].'" width="32px" height="32px" ><h2><a href="searchbycat.php?catagory='.$enc.'&maincateg='.$enc.'&maincatid='.$v['id'].'&city=$city">'.$maincatagory.'</a></h2>';
                              else
                              echo '<div class="subcatagoriesleft"><img src="/backend/images/default.png" width="32px" height="32px" ><h2><a href="searchbycat.php?catagory='.$enc.'&maincateg='.$enc.'&maincatid='.$v['id'].'&city=$city">'.$v['MainCatagory'].'</a></h2>';

                                 $sql1 = mysql_query("select DISTINCT sub.Subcatagory,sub.id,sub.MainCatid,ck.MainCatagory from subcatagorykeywords sub JOIN catagorykeywords ck ON ck.id=sub.MainCatid where sub.MainCatid='$catid' ORDER BY sub.id DESC LIMIT 0,10");


                                  echo '<div class="subcat_tick"><ul>';
                                      while($v1= mysql_fetch_array($sql1))
                                      {
                                          $subcategory = $v1['Subcatagory'];
                                          $position=20; 
                                          $Subcatagory11 = substr($subcategory, 0, $position);
                                          $maincat = $v1['MainCatagory'];
                                          $encr = urlencode($maincat);
                                      echo '<li><a href="searchby_subcat.php?catagory='.$v1['Subcatagory'].'&subcatagory='.$v1['Subcatagory'].'&subcatid='.$v1['id'].'&maincatid='.$v1['MainCatid'].'&maincateg='.$encr.'&city=$city">'.$Subcatagory11.'</a></li>';
                                      }
                                  echo '</ul></div>';

                                   $sql12 = mysql_query("select DISTINCT Subcatagory,id,MainCatid from subcatagorykeywords where MainCatid='$catid' ORDER BY id DESC");
                                   $count1 = mysql_num_rows($sql12);

                                  if($count1>10)
                                  {
                              echo '<div class="toggle">
                              <div class="toggle_content">';
$sql9 = mysql_query("select DISTINCT sub.Subcatagory,sub.id,sub.MainCatid,ck.MainCatagory from subcatagorykeywords sub JOIN catagorykeywords ck ON ck.id=sub.MainCatid where sub.MainCatid='$catid' ORDER BY sub.id DESC LIMIT 10,30");

                                  echo '<div class="subcat_tick"><ul>';
                                      while($v9= mysql_fetch_array($sql9))
                                      {
                                          $subcategory = $v9['Subcatagory'];
                                          $position=20; 
                                          $Subcatagory11 = substr($subcategory, 0, $position);
                                          $maincatt = $v9['MainCatagory'];
                                          $encrr = urlencode($maincatt);
                                      echo '<li><a href="searchby_subcat.php?catagory='.$v9['Subcatagory'].'&subcatagory='.$v9['Subcatagory'].'&subcatid='.$v9['id'].'&maincatid='.$v9['MainCatid'].'&maincateg='.$encrr.'&city=$city">'.$Subcatagory11.'</a></li>';
                                      }
                                  echo '</ul></div>';

echo '</div><h4 class="toggle_title"><span class="toggle_indicator"></span>Read more</h4></div>';
                                }
                                echo '</div>';
                            } 
                         ?>



                      <div class="home_tab_page">
                        <?=$pagination;?>
                      </div>                

                <link rel="stylesheet" id="shortcodes-css-css" href="r-script/scoll/shortcodes.css" type="text/css" media="all">
<script type="text/javascript" src="r-script/scoll/jquery_007.js"></script>
<script type="text/javascript">
/* <![CDATA[ */
var _wpcf7 = {"loaderUrl":"http:\/\/www.redcamel.in\/wp-content\/plugins\/contact-form-7\/images\/ajax-loader.gif","sending":"Sending ..."};
/* ]]> */
</script>
<script type="text/javascript" src="r-script/scoll/scripts.js"></script>
<script type="text/javascript" src="r-script/scoll/shortcodes.js"></script>
<script type="text/javascript">
function wp_attempt_focus() {
setTimeout( function() {
try {
d = document.getElementById('user_login');
d.value = '';
d.focus();
} catch(e){}
}, 200 );
}
wp_attempt_focus();
if(typeof wpOnload=='function')wpOnload()
</script>




                </div>
             <!-- Contents Tab1 Ends here -->

            <!-- Contents Tab2 Begins here -->   

                <div style="display: block;" id="country2" class="other_tabs" >


                  <?php include("db.php");
                  $tbl_name="article";      //your table name
    // How many adjacent pages should be shown on each side?
    $adjacents = 3;

    /* 
       First get total number of rows in data table. 
       If you have a WHERE clause in your query, make sure you mirror it here.
    */

    $query = "SELECT count(DISTINCT ac.ArticleCategory,ac.id,a.ArticleTitle) as num FROM articlecategory ac JOIN article a ON a.Catagoryid=ac.id WHERE Publish=1";
    $total_pages = mysql_fetch_array(mysql_query($query));
    $total_pages = $total_pages[num];

    /* Setup vars for query. */
    $targetpage = "index.php?city=$city&article";   //your file name  (the name of this file)
    $limit = 5;                                 //how many items to show per page
    $page = $_GET['page'];
    if($page) 
        $start = ($page - 1) * $limit;          //first item to display on this page
    else
        $start = 0;                             //if no page var is given, set start to 0

    /* Get data. */

                $sql3 = mysql_query("select DISTINCT ac.ArticleCategory,ac.id,a.ArticleTitle from article a JOIN articlecategory ac ON a.Catagoryid=ac.id  LIMIT $start,$limit");
                $result = mysql_query($sql3);
    /* Setup page vars for display. */
    if ($page == 0) $page = 1;                  //if no page var is given, default to 1.
    $prev = $page - 1;                          //previous page is page - 1
    $next = $page + 1;                          //next page is page + 1
    $lastpage = ceil($total_pages/$limit);      //lastpage is = total pages / items per page, rounded up.
    $lpm1 = $lastpage - 1;                      //last page minus 1

    /* 
        Now we apply our rules and draw the pagination object. 
        We're actually saving the code to a variable in case we want to draw it more than once.
    */
    $pagination = "";
    if($lastpage > 1)
    {   
        $pagination .= "<div class=\"pagination\">";
        //previous button
        if ($page > 1) 
            $pagination.= "<a href=\"$targetpage&page=$prev\"> Previous</a>";
        else
            $pagination.= "<span class=\"disabled\"> Previous</span>";    

        //pages 
        if ($lastpage < 7 + ($adjacents * 2))    //not enough pages to bother breaking it up
        {   
            for ($counter = 1; $counter <= $lastpage; $counter++)
            {
                if ($counter == $page)
                    $pagination.= "<span class=\"current\">$counter</span>";
                else
                    $pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";                   
            }
        }
        elseif($lastpage > 5 + ($adjacents * 2))    //enough pages to hide some
        {
            //close to beginning; only hide later pages
            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\">$counter</a>";                   
                }
                $pagination.= "...";
                $pagination.= "<a href=\"$targetpage&page=$lpm1\">$lpm1</a>";
                $pagination.= "<a href=\"$targetpage&page=$lastpage\">$lastpage</a>";     
            }
            //in middle; hide some front and some back
            elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
            {
                $pagination.= "<a href=\"$targetpage&page=1\">1</a>";
                $pagination.= "<a href=\"$targetpage&page=2\">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\">$counter</a>";                   
                }
                $pagination.= "...";
                $pagination.= "<a href=\"$targetpage&page=$lpm1\">$lpm1</a>";
                $pagination.= "<a href=\"$targetpage&page=$lastpage\">$lastpage</a>";     
            }
            //close to end; only hide early pages
            else
            {
                $pagination.= "<a href=\"$targetpage&page=1\">1</a>";
                $pagination.= "<a href=\"$targetpage&page=2\">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\">$counter</a>";                   
                }
            }
        }

        //next button
        if ($page < $counter - 1) 
            $pagination.= "<a href=\"$targetpage&page=$next\">Next </a>";
        else
            $pagination.= "<span class=\"disabled\">Next </span>";
        $pagination.= "</div>\n";        
    }


                       while($v3 = mysql_fetch_array($sql3))
                        {
                            $take = $v3['ArticleTitle'];
                          $catagory = $v3['ArticleCategory'];
                          $articlecatid = $v3['id'];
                          if(!$take = '')

                          echo '<a href="articlesbycat.php?catagory='.$v3['ArticleCategory'].'&id='.$v3['id'].'" style="text-decoration:none;"><div class="tabdisp_articles"><h2>'.$v3['ArticleCategory'].'</h2></a>';




    $count = $_GET['counting'];
    $articleid = $_GET['id'];
    $sql5 = mysql_query("UPDATE article SET Count='$count'+1 WHERE Id='$articleid'");

                            $sql4 = mysql_query("SELECT * FROM article a JOIN articlecategory ac ON ac.id=a.Catagoryid WHERE a.Publish=1 AND a.Catagoryid='$articlecatid' ORDER BY a.Id DESC LIMIT 2");

    //$result = mysql_query($sql4);

                             //WHERE Catagoryid='$articlecatid' AND Publish=1 ORDER BY Id DESC
                              echo '<ul>';
                                  while($v4= mysql_fetch_array($sql4))
                                  {
                                  echo '<li><a href="articles.php?id='.$v4['Id'].'&catagory='.$v4['ArticleCategory'].'&catagoryid='.$v4['Catagoryid'].'&articletitle='.$v4['ArticleTitle'].'&counting='.$v4['Count'].'" onclick="counting()">'.$v4['ArticleTitle'].',</a></li>';
                                  }
                              echo '</ul>';
                              echo '<div class="readmore"><a href="articlesbycat.php?catagory='.$v3['ArticleCategory'].'&id='.$v3['id'].'">Read More</a></div>';
                          echo '</div>';


                         } ?>


                    <!--<div class="article" >
                        <h2>Most Recently Added Articles</h2>
                        <?php
                            include("db.php");
                            $sql2 = mysql_query("select * from article where Publish=1 order by Id desc LIMIT 10 ");

                           echo '<ul>';  
                           while($v2 = mysql_fetch_array($sql2))
                            {
                            echo '<li><a name="id" id="id" href="articles.php?id='.$v2['Id'].'">'.$v2['ArticleTitle'].'</a></li>';
                            }
                            echo '</ul>';

                         ?>
                    </div>-->
                    <div class="home_tab_page">
                      <?=$pagination?>   
                </div>                
                </div>

           <!-- Contents Tab2 Ends here -->
  </div>
  </div>

Sounds that you need Ajax. Attach a Javascript event to the links you need to get pagination. Pass some vars to server via Aja which determines to get which data and where.

A Javascript function may look like, in case I juse jQuery for this example.

$.ajax({
    url: 'ajax.php',
    type: 'GET',
    data: {rel: 'something'}, // pass the rel to server and server can serve what to do depends on rel value (country1, country2 etc.)
    beforeSend: function() {
        // before sending Ajax request to server, you may create loading progress here according to your DOM structure
        console.log('Sending to server.');
    },
    error: function(xhr, textStatus, errorThrown) {
        // there is an error returns by server, you can use some DIV to show the error
        console.log('Error: ' + errorThrown);
    },
    success: function(data) {
        // replace your new data into your container
        $('#ajax-container').html(data);
    }
});

In ajax.php

<?php

// get the rel
$rel = $_GET['rel'];

$rel = ( $rel ) ? $rel : 'default_value'; // make sure you've default value

switch( $rel ) {

    case 'country1':
        break;
    case 'country2':
        break;
    default:

}

This is just an example to get an idea, you've to do more work to implement this. Pass also require stuffs for pagination and update them with Javascript upon server response, and so on.

I found out some WordPress functions inside your codes and if you're using WordPress, use WordPress Ajax hook and use it's query functions. It has $wpdb, a global database object to touch with database query. You can create your new database object if you're using another database, for example:

$mydb = new wp_db($user, $pass, $db, $host);
$mydb->query($mydb->prepare("SELECT something FROM some_table WHERE some_field = some_value"));

Check WordPress Codex, if you need it, and googling for Ajax would also help to you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.