SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2011
    Location
    California
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Add 10 To The Limit?

    Hello,

    I am attempting to create a dynamic LIMIT clause in an SQL query, but to no prevail.

    Basically, I have a query selecting all of the posts from a table called "posts".
    From there, I have a LIMIT statement saying to limit it to whatever a variable called "pages" is equaled too.

    Code:
    $page = $_GET["page"] + 9;
    $q1 = $link->query("SELECT * FROM posts ORDER BY id DESC LIMIT $page");
    So from the above, I want it to display all of the posts that were the first 1 - 10.
    (The page always has a GET variable "?posts=1".)

    Well, this isn't working exactly how I wanted it to work.
    You see, I want it to select 1 through 10 if $pages = 1.
    If pages is equaled to 2, I want it to select from 11 to 20... And so forth.

    How could I do this?

    Thanks,
    Eric

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2011
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to use OFFSET. Check this tutorial about paging using php

  3. #3
    SitePoint Member
    Join Date
    Sep 2011
    Location
    California
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much!


Bookmarks

Posting Permissions

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