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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:36:55+00:00 2026-06-19T00:36:55+00:00

i have an xml file which contains around 60 books which i need to

  • 0

i have an xml file which contains around 60 books which i need to put into ascending order from the borrowedcount using php so far my code shows all the books but will not sort? any help would be really appriecated

PHP

<?php


$xmlassignDoc = new DOMDocument();
$xmlassignDoc->load("books.xml");


$books = $xmlBookDoc->getElementsByTagName("item");

foreach($books as $list)
{
    $course = $list->getElementsByTagName("course");
    $course = $course->item(0)->nodeValue;


//HERE is where the GET function will be
    if ($course == "CC150")
    {

    print_r($array);
        $id = $list->getAttribute("id");
        echo "<b>Book ID: </b> $id <br>";

         $title = $list->getElementsByTagName("title");
         $title = $title->item(0)->nodeValue;
         echo "<b>Title: </b> $title <br>";

         $isbn = $list->getElementsByTagName("isbn");
         $isbn = $isbn->item(0)->nodeValue;
         echo "<b>ISBN: </b> $isbn <br>";

         $borrowed = $list->getElementsByTagName("borrowedcount");
         $borrowed = $borrowed->item(0)->nodeValue;
         echo "<b>Borrowed Count: </b> $borrowed <br>";
         echo "<br>";
    } 
}
//print $xmlBookDoc->saveXML();
?>

xml file

<?xml version="1.0" encoding="utf-8"?>
<bookcollection>
<items>
  <item id="51390">
     <title>Management of systems development /</title>
     <isbn>0091653215</isbn>
     <url>http://library.hud.ac.uk/catlink/bib/51390</url>
     <borrowedcount>45</borrowedcount>
     <courses>
        <course>CC140</course>
        <course>CC210</course>
     </courses>
  </item>
  <item id="483">
     <title>Database systems management and design /</title>
     <isbn>0877091153</isbn>
     <url>http://library.hud.ac.uk/catlink/bib/483</url>
     <borrowedcount>28</borrowedcount>
     <courses>
        <course>CC140</course>
     </courses>
  </item>
  <item id="585842">
     <title>E-learning skills /</title>
     <isbn>0230573126</isbn>
     <url>http://library.hud.ac.uk/catlink/bib/585842</url>
     <borrowedcount>5</borrowedcount>
     <courses>
        <course>CC157</course>
     </courses>
  </item>

  • 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-06-19T00:36:56+00:00Added an answer on June 19, 2026 at 12:36 am

    My solution:

    $books = array();
    
    $xml = simplexml_load_file('books.xml'); 
    
    foreach($xml->items->item as $item) {
        $books[] = array(
                         'id'             => (string)$item->attributes()->id,
                         'title'          => (string)$item->title,
                         'isbn'           => (string)$item->isbn,
                         'course'         => (string)$item->courses->course[0],
                         'borrowed_count' => intval($item->borrowedcount)
                        );
    }
    
    
    array_sort_by_column($books, 'borrowed_count');
    
    var_dump($books);
    

    And the sorting function:

    function array_sort_by_column(&$array, $column, $direction = SORT_ASC) {
        $reference_array = array();
    
        foreach($array as $key => $row) {
            $reference_array[$key] = $row[$column];
        }
    
        array_multisort($reference_array, $direction, $array);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have books.xml file which contains author name and book titles. I am using
I have an XML file which I need to parse using PHP and send
I have an XML file which contains data from a SQL DataSource . I
I have this xml file which contains information from tagchimp, but the file contains
I have a xml file which contains data I want to insert into a
I have written xml file which contains html tags as element like <component> <input
I have a xml file which contains arabic characters.When i try to parse a
I have an XML file of(30GB) which contains 2 classes of data, The data
I have a problem parsing a XML file which contains special characters like ,
I have a XML-file, which contains the data of a calendar. I want to

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.