Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2003
    Location
    Minnesota
    Posts
    61

    Thumbs up Unanswered: Display 10 Records Per Page

    I want to display only ten records per page.
    How do i do this with a dsn-less connection?
    Mr. Lars

  2. #2
    Join Date
    Jun 2003
    Posts
    20
    you can set a variable that counts the records in the while loop. Then pass the variable to the next page and use it to find your starting point.

    don't know what language you are in, so this is pseudo:

    $var=0;
    start=$start;
    while(Rrecordset) {
    $var = $var +1;
    if ($var< $start) next;
    if $var=10 end while;
    }


    <a href=next.asp?start=var>next</a>

    hope this helps.

  3. #3
    Join Date
    Jun 2003
    Location
    Minnesota
    Posts
    61
    Thanks a lot! It helped me figure out the idea and I also found another site that helped me as well. The code I wanted to use was asp.
    Mr. Lars

  4. #4
    Join Date
    Jun 2003
    Location
    México
    Posts
    5

    Re: Display 10 Records Per Page

    Originally posted by lslars31
    I want to display only ten records per page.
    How do i do this with a dsn-less connection?
    An other good idea is to use the sentence LIMIT in your QUERY, In this way you don't need to request all the rows only 10 could be submitted and the listed in the web page.

    SELECT * FROM my_table WHERE name LIKE 'C`%' LIMIT 0,10
    SELECT * FROM my_table WHERE name LIKE 'C`%' LIMIT 10,10
    SELECT * FROM my_table WHERE name LIKE 'C`%' LIMIT 20,10
    .
    .
    and go on

  5. #5
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3
    Just posted something like this on our forums for a customer, although it was in PHP so I've converted it to a bit of psudo like (only just) code for you, so you'll have to convert it properly to ASP.
    Code:
    dbcnx = mysql_connect('**********','***','****'); 
    mysql_select_db('*****'); 
    
    perpage = 10; 
    page = (isset($_GET['page'])) ? $_GET['page'] : 1; 
    start = (page - 1) * perpage; 
    result = mysql_query("SELECT * FROM shared LIMIT " + start +"," + perpage); 
    if (result) { 
      //Problems reading data
    } 
    
    res2 = mysql_query("SELECT COUNT(*) AS count FROM table"); 
    data = mysql_fetch_array( res2 ); 
    pages = (data['count'] / perpage) + (((data['count'] % perpage) > 0) ? 1 : 0);
    Hope that helps you out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •