I have a CMS that creates an XML file for each article submitted. I use the following code to display a list of the articles with their headers etc but have two changes I would like to make to it.
Firstly, how can I reverse the order they are loaded? Currently it loads the most recently created article first but I would like this the other way around.
Secondly, is there a way I can set it to load from a certain number? So for example, it skips the first 12 then loads the next 5?
Looks like your using readdir() to cycle through the files. The documentation for that function says "The filenames are returned in the order in which they are stored by the filesystem" so it doesn't sound like using that function is an effective way to do what you want. http://ca3.php.net/manual/en/function.readdir.php
Is a record of the articles in a database somewhere? That would make things much easier.
I suppose you could use readdir() to read in the entire directory contents to an array then manipulate it to get what you want, but a database would be best.
Looks like your using readdir() to cycle through the files. The documentation for that function says "The filenames are returned in the order in which they are stored by the filesystem" so it doesn't sound like using that function is an effective way to do what you want. http://ca3.php.net/manual/en/function.readdir.php
Is a record of the articles in a database somewhere? That would make things much easier.
I suppose you could use readdir() to read in the entire directory contents to an array then manipulate it to get what you want, but a database would be best.
Unfortunately I'm not using a database for this at the moment. I know that it would be far far better and I am trying to get my head around MySQL at the moment but for the sake of this project I need to get it functional asap.
Could you suggest how I may go about using a manipulated array?
Ok, I haven't quite figured out why that isn't working, however, I don't think it would do what I need to anyway. As I don't want to post the whole content of each .xml file and I want to add structuring to certain parts as I do it (as in the latter part of my op).
What I'm now wondering is if it would work if I were to find a way to open the directory and assign it to a var, then set that into an array, reverse the order of that array then pass that into the var that is accessed by the readdir?
I had forgotten to adjust the rout before but its pointing to the right directory now. I have three files so this should emit the first and display the contents of the second two, however, it is simply printing the names of the two files:
Ok, so what I basically need to figure out the syntax for is this:
- Grab the names of each file in said directory
- Set them into an array
- Reverse the order of the array
- Call a function which extracts specific elements from the file relative to the first item in the array
- Repeat this function for the next 4(for example) items in the array, then stop.