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 6678761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:16:50+00:00 2026-05-26T04:16:50+00:00

Trying to make it so that the glob function displays only the first 10

  • 0

Trying to make it so that the glob function displays only the first 10 results (text files from a folder) and then automatically the next 10 with a next button.

Currently, I used array_slice to display only the first 10, but I’m not sure how to automate the process.

foreach(array_slice(glob("*.txt"),0,9) as $filename) {
   include($filename); }

Oh and while I’m at it, if possible, display something like “displaying 1-10” and last/first links. I could probably figure that out myself after I get past the first obstacle, so don’t bother with this unless it’s a super easy solution.

  • 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-26T04:16:51+00:00Added an answer on May 26, 2026 at 4:16 am

    What you’re trying to accomplish is called pagination. From your example, you can dynamically choose which ten you’re viewing by setting a variable that determines what number (file) to start at.

    Example:

    <?php
    $start = isset( $_GET['start']) ? intval( $_GET['start']) : 0;
    
    $glob_result = glob("*.txt");
    $num_results = count( $glob_result);
    
    // Check to make sure the $start value makes sense
    if( $start > $num_results)
    { 
        $start = 0;
    }
    
    foreach( array_slice( $glob_result, $start, 9) as $filename) 
    {
         include( $filename); // Warning!
    }
    

    If you only want to do increments of 10, you can add a check to make sure $start is divisible by 10, something like this after $start is retrieved from the $_GET array:

    $start = ( $start % 10 == 0) ? $start : 0;
    

    Now, for links, all you need to do is output <a> tags that have the start parameter set correctly. You will have to do some logic to calculate the next and previous values correctly, but here is a simple example:

    $new_start = $start + 10;
    echo '<a href="page.php?start=' . $new_start . '">Next</a>';
    

    Edit: As the comments above suggest, you probably do not want to include() these files, as include() will attempt to interpret these files as PHP scripts. If you just need to get the contents of the text files, use file_get_contents instead.

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

Sidebar

Related Questions

Im trying to make a function that will return an element of type point:
I'm trying to make a calculator that will take inputs from users and estimate
I'm trying to make a webpage that allows the uploading of multiple files at
I'm trying to make a glob-like expansion of a set of DNA strings that
Im trying to rezise some images that are imported from a folder. It doesent
I am trying to make a function that opens a window but makes sure
I am trying to make a function call using the data I read from
I am currently trying to make sure that a member function of one class
I am trying to write my first real python function that does something real.
I'm trying to make sure that the first name and last name field are

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.