Get variables from the first 10 pages in descending order [closed]

-1

We assume that in a folder there are 11 files renamed with numbers (1.php, 2.php ... 11.php) and all of them have variables with equal names but different values (1.php: var="texto1" ... 2.php: var="texto2"), I need a condition that opens only the first 10 pages in descending order and a echo in the variable of the first 10, and also a small page navigation system, type: button 1 → from page 1 to 10, button 2 → page 11 to 21 and that these buttons exist in the proportion of pages that exist in the folder, similar to the Google search buttons to find more results:

No need to use database.

    
asked by anonymous 24.09.2018 / 00:06

1 answer

1

To get the list of files in a folder use glob ()

$arquivos = glob('/caminha/da/pasta/*.php');

Then, use array_slice () to get only the top 10:

$arquivos = array_slice($arquivos, 0, 10);

Finally, use a foreach to print the value of the variables found. Something like:

foreach ($arquivos as $arquivo){
    include($arquivo);
    echo $var; //Variável que está dentro de arquivo
}

About paging, I recommend giving a look at other sites on how to do a paging. I just typed in google "paging with php from array" and got a list with lots of stuff ready. One of the videos listed is the following (not watched): link

NOTE: The codes I gave are just for study and give you guidance on what to study. I do not recommend using them on any production systems.

    
24.09.2018 / 17:02