Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7530695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:58:51+00:00 2026-05-30T04:58:51+00:00

I have an article system which is used by several users. Articles have their

  • 0

I have an article system which is used by several users. Articles have their own permissions which gets checked against the viewer’s ID for each article that runs through my while loop. I limit the articles by incrementing $printcount if the user is allowed to view the article, and the loop terminates when it reaches $limit. I also have sorting options to sort by name, date inserted, date modified and submitted by.

How would I go about utilizing next/previous page buttons without using MySQL limit features? Here is a short version of my code (may not be 100% functional, but should bring the point across)

<?php
$sort=$_GET['sort']; // date_added
$direction=$_GET['dir']; // ASC
$limit=$_GET['limit']; // 25
$query="SELECT * FROM `article` ORDER BY '$sort' '$direction'";

$result=mysql_query($query);
if(mysql_num_rows($result)==NULL) {
  echo '<tr><td colspan="4">NO RECORDS FOUND</td></tr>';
}
$printcount=0;
while(($row=mysql_fetch_assoc($result))&&($printcount<$limit+1)) {
  //if user is owner of article $readable=true;
  //load permissions from permission column (comma separated integers) into array, if user's group ID is in that array $readable=true;
  //if article "global_read" flag=1, $readable=true;
  //if $printcount<$limit, and $readable echo the table row with data
  //if $readable, $printcount++;
}
?>

If I were only sorting by ID ASC, I could easily store the ID as a last_id, and on next page the query would have an additional: WHERE `id` > $last_ID, but since there are different sort options and direction options this seems to be much more complicated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:58:53+00:00Added an answer on May 30, 2026 at 4:58 am

    I’m assuming you’re asking this question because your permission model is handled in the php application and prevents you from easily using LIMIT in your queries.

    You should store the per-user permissions in the database table, and then use a join so that only the articles that a user can view are retrieved. Then you don’t have to handle the pagination or sorting logic in your application; you can just use LIMIT and ORDER BY in mysql to do it for you.

    Also you should probably use the parameter-based queries. Your code has a massive sql injection hole.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that used another php cms system, which I am now
In a content management system, moderators have to approve changes to existing articles. Currently
I have a system which is receiving around 15 million records every day (in
I have model Article it has field title with some text that may contain
Say that I have an article with multiple pages. Each page has a short
I have lots of article store in MS SQL server 2005 database in a
I have followed this article and implemented my service and I can open the
Anyone have good book / article recommendation for procedural generation of background music? (No
I have read this article from High Scalability about Stack Overflow and other large
I have read this article about 400% boost of your website . This is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.