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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:08:09+00:00 2026-05-21T14:08:09+00:00

I am trying to create a weighted banner system for my website. This is

  • 0

I am trying to create a weighted banner system for my website.

This is my XML:

<banners>
    <images>
        <src>banners/ad_1.png</src>
        <alt>Banner ad 1</alt>
        <views>9</views>
    </images>
    <images>
        <src>banners/ad_2.png</src>
        <alt>Banner ad 2</alt>
        <views>9</views>
    </images>
</banners>

I want to display the image with the lowest view. Once I have that image, increment the view to show that the banner has been shown.

I don’t want to use simpleXML. All the dom manipulation will directly be using this $dom variable:

$dom = new DOMDocument();
$dom->load($file_name);

I have been at this for over 3 hours and my code just keeps getting bigger and bigger. I have figured out how to increment it and place it back into the XML file. I just don’t know how to pull the image that has the lowest views for display.

Any help, even ideas would be GREATLY appreciated!

  • 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-05-21T14:08:10+00:00Added an answer on May 21, 2026 at 2:08 pm
    $images = $dom->getElementsByTagName("images"); //Grab all image nodes
    $views = array(); //Set up array for src and viewcount data
    foreach($images as $image){ //Loop through all image nodes
       $src = $image->getElementsByTagName("src")->nodeValue; //Get the src
       $views[$src] = $image->getElementsByTagName("views")->nodeValue; //Add the viewcount to the array and use src as the array key
    }
    asort($views); //Sort the array by viewcount (low->high)
    $src = array_keys($views); //Extract keys (or src)
    
    $lowestViews = $views[0]; //Var for lowest number of views
    $lowestSrc = $src[0]; //Var for the src of the lowest viewed image
    

    I hope that helps! Sorry for mega commenting. Got bored.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a weighted search using doctrine. This is how i
I trying create a class derivated from System.Web.UI.Page and in override Render i set
Trying to create the following routine in MySQL Workbench yields a This object's DDL
I'm trying create this function such that if any key besides any of the
I'm trying to create a 2D array to represent a weighted graph. To make
I'm trying create a log specifically for logging user account activity. I created this
I'm trying create an immutable object and initialise it from xml config file in
I am trying create a table and add this table into tablecell (table inside
I'm trying create a regex that verifies an xml entity name is valid (see
I'm trying create a small http proxy service. This is not working so well.

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.