1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

a little help with ASP paging

Discussion in 'C#' started by Kyriakos, Jun 14, 2013.

  1. #1
    hi,

    i have an online store builded in classic ASP. i have this script for paging the products (10 items per page).
    SEMrush
    if ppp = "" then ppp=10
    
    cSQL = "SELECT COUNT(*) AS rows FROM products WHERE cat='"&cat&"' AND active=1"
    
    set cRS=con.execute(cSQL)
    myrows = Cint(cRS("rows"))
    
    sql = "SELECT * FROM products WHERE cat='"&cat&"' AND active=1 ORDER BY "&ord&" LIMIT "&(pg-1)*ppp&", "&ppp
    
    set prodRS=con.execute(sql)
    
    nmpages=myrows/ppp
    nmpg = Round(nmpages)
    if nmpg < nmpages then
    nmpg = nmpg + 1
    end if
    
    
    'pagination
    for i = 1 to nmpg
    if i <> cINT(pg) then
    response.Write(" <a href=""?cat="&cat&"&pg="&i&""">"&i&"</a>")
    end if
    next
    Code (markup):
    In some categories i have a lot of products and i have a huge number of pages (eg: 128 pages for 1280 products in one category).

    I want to display the pages like some forums
    eg: 1 2 3 4 5 82 105 128 (when the selected page = 1)
    or 1 32 48 49 50 51 52 94 110 128 (when the selectet page = 50)
    or: 1 64 98 99 100 101 102 120 128 (when the selectet page = 100)
    etc...

    i have the script for next, previous, first, last pages. i want only some script for the example above.

    thanks in advance.
     
    Kyriakos, Jun 14, 2013 IP
    SEMrush
  2. wren11

    wren11 Active Member

    Messages:
    89
    Likes Received:
    10
    Best Answers:
    3
    Trophy Points:
    53
    #2
    you need to use a higher adjacent value when building the pagination.
     
    wren11, Jun 17, 2013 IP
  3. Kyriakos

    Kyriakos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    what do you mean? can you show me any example?
     
    Kyriakos, Jun 18, 2013 IP
  4. wren11

    wren11 Active Member

    Messages:
    89
    Likes Received:
    10
    Best Answers:
    3
    Trophy Points:
    53
    #4
    Something Like this maybe? written in c# as an example


    
    namespace pagination
    {
        using System;
        using System.Linq;
        using System.Text;
    
        class Program
        {
            static void Main(string[] args)
            {
    
                StringBuilder results = new StringBuilder();
    
                var items = Enumerable.Range(1, 1280).ToArray();
    
                var adjacent = 3;
                var limit = 10;
                var page = 50;
                var start = (page - 1) * limit;
    
                if (page == 0)
                    page = 1;
    
                var lastpage = Math.Ceiling((double)items.Length / limit);
    
                if (lastpage > 1)
                {
                    if (lastpage < 7 + (adjacent * 2))
                    {
                        for (int i = 1; i <= lastpage; i++)
                        {
                            if (!(i == page))
                            {
                                results.Append(i);
                            }
                        }
                    }
                    else if (lastpage > 5 + (adjacent * 2))
                    {
                        if (page < 1 + (adjacent * 2))
                        {
                            for (int i = 1; i < 4 + (adjacent * 2); i++)
                            {
                                if (!(i == page))
                                {
                                    results.Append(i);
                                }
                            }
                        }
                        else if (lastpage - (adjacent * 2) > page && page > (adjacent * 2))
                        {
                            results.Append(1);
                            results.Append(2);
    
                            for (int i = page - adjacent; i <= page + adjacent; i++)
                            {
                                if (!(i == page))
                                {
                                    results.Append(i);
                                }
                            }
                        }
                        else
                        {
                            results.Append(1);
                            results.Append(2);
    
                            for (int i = (int)lastpage - (2 + (adjacent * 2)); i <= lastpage; i++)
                            {
                                if (!(i == page))
                                {
                                    results.Append(i);
                                }
                            }
                        }
                    }
                }
    
    
                Console.WriteLine(results.ToString());
            }
        }
    }
    
    
    PHP:
     
    wren11, Jun 18, 2013 IP
  5. Kyriakos

    Kyriakos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    i don't know C#. my site is written in ASP language.
     
    Kyriakos, Jun 18, 2013 IP
  6. Kostyantyn

    Kostyantyn Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #6
    Hello, Kyriakos!

    Sorry, your code block shows selection items from database and calculates total amount of pages, so it is not applicable to what you want to be done :(

    Pager - another control on your page and modification should affect its behavior.
     
    Kostyantyn, Jun 19, 2013 IP