Pick variables from the first 10 pages in descending order

Asked

Viewed 44 times

-1

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

inserir a descrição da imagem aqui

No need to use database.

  • Can I get you anything else? Let me know

  • Não kkkk is like a blog start that I want to do and I just need a base made to study understand

  • I think this is not the best way to study, but anyway, this is just my opinion.

  • I understand, but I like it this way having a base, I find it more interesting

1 answer

1


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

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

then, use array_slice() to catch only the first 10:

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

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

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

About paging, I recommend doing a search on other sites about how to make a pagination. I just wrote in google "pagination with php from array" and has a list with lots of ready material. One of the listed videos is as follows (not watched): https://www.youtube.com/watch?v=UUH8PA9OvtI

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

  • Thank you, actually I study on my own, I’m going to college but it’s something else kkk

  • Hehe, no problem. I who expressed myself badly then, I will be editing the end of the answer ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.