Note that there are some explanatory texts on larger screens.

plurals
  1. POOrder SimpleXML entries alphabetically
    primarykey
    data
    text
    <p>here it's my first question on stackoverflow. i usually try to look up for an answer by myself, but it seems this time i'm stuck.</p> <p>a little background about myself first : i have no deep knowledge of php whatsoever, I do however work on a daily basis with css and html. i have a good understanding on how loops works , if for while statements and such (have worked a bit with python and pascal in the years). I'm now attempting to widen my web-design knowledge with php.</p> <p>as an excercise for myself i'm currently attempting to make my own movie library. i did that already in html (hello useless work) and now i'm converting it in php/simplexml. looking at php.net and other online resources i managed to pull off the following structure:</p> <p>XML</p> <pre><code>&lt;film&gt; &lt;title&gt;Great Movie&lt;/title&gt; &lt;link&gt;http://imdb.com/#&lt;/link&gt; &lt;poster&gt;img-name&lt;/poster&gt; &lt;year&gt;2012&lt;/year&gt; &lt;/film&gt; </code></pre> <p>repeated for every movie i have, and of course all is inside a root tag <code>&lt;film&gt;&lt;/film&gt;</code></p> <p>the php instead is as follow :</p> <pre><code>&lt;ul&gt; &lt;?php $xml = new SimpleXMLElement ('database.xml',NULL,true); foreach($xml-&gt;film as $movie) { echo "&lt;li&gt;\n"; echo "&lt;div class=\"film_container\"&gt;\n"; echo "&lt;div class=\"poster\"&gt;\n"; echo "&lt;a href=\"".$movie-&gt;link."\"&gt;&lt;img src=\"img/".$movie-&gt;poster.".jpg\" /&gt;&lt;/a&gt;\n"; echo "&lt;/div&gt;"; echo "&lt;div class=\"info\"&gt;\n"; echo "&lt;h2&gt;".$movie-&gt;title."&lt;/h2&gt;\n"; echo "&lt;p&gt;".$movie-&gt;year."&lt;/p&gt;\n"; echo "&lt;/div&gt;\n"; echo "&lt;/div&gt;\n"; echo "&lt;/li&gt;\n"; } ?&gt; &lt;/ul&gt; </code></pre> <p>again, very simple. this just let me layout all the info i needed and then style them with a css.</p> <p>now, the tricky part comes. because i had already 200+ movies in my html library, they were all manually-listed alphabetically (yes, i know..) and it would seems rather pointless to start now appending new entries with no order, but for future reference, I wanted to know if there is a way to , just by appending a new entry at the end of the xml it is then automatically placed in the right place when going through the loop.</p> <p>i have look quite extensively over the internet, and yes, i found multiple solution to alphabetically sort your entries, but those worked when you then print out the result of the sorting (e.g. i sort all movies by name, then i can print out the whole list of movies alphabetically sorted with the var_dump function), but I have absolutely no idea what to put in the foreach statement after i sorted them out to go through the xml again and read each of them separately.</p> <p>thanks in advance to everyone for, well, simply reading my wall of text. I'm sorry if I wrote too much, but I didn't know how else explain myself. I'm quite sure the answer will be something on the line 'it's very simple, you just overlooked that part in the manual..' </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload