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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:57:10+00:00 2026-05-23T15:57:10+00:00

Using SimpleXML to pull data from a basic XML file. The XML looks something

  • 0

Using SimpleXML to pull data from a basic XML file. The XML looks something like:

<shop>
  <section>
    <title></title>
    <products>
      <item>
        ...
      </item>
    </products>
  </section>
</shop>

I can load and loop out the nodes, but when I populate the HTML with each sections items it keeps repeating the first sections items. I’m confused because each section name is outputting correctly but using the first set of items.

foreach($xml->section as $section){
$i=0;
echo '<div class="section"><div class="sectionTop"><h3>'.$section->title.'</h3><a class="expand">+/-</a></div>';         

foreach($xml->section->products as $products){
    foreach($products->item as $item){
        if($i==3){echo '</div><div class="extra">';}?>

        <div class="item">
        <img src="<?=$item->image?>" />
        <div class="prodName"><?=$item->name?></div>
            <div class="price">&pound;<?=$item->price?></div>
        <a href="<?=$item->url?>" class="shopNow">SHOP</a>
    </div>

        <? 
        $i++;
        unset($item);
    }
    unset($products);
}

Can anybody help? This where I am so far, unset doesn’t work 🙁 <shop> is $xml

  • 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-23T15:57:11+00:00Added an answer on May 23, 2026 at 3:57 pm

    You should use $section variable to count it products.

    So
    foreach($xml->section->products as $products){
    ->
    foreach($section->products as $products){

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

Sidebar

Related Questions

I'm using SimpleXML to parse a data file from an external source. I'm trying
I am trying to unmarshall data from an XML object in Java using SimpleXML.
I am Parsing XML currently using: $data = simplexml_load_string($xmlFile); foreach($data->item as $key => $current){
I'm using simpleXML to add in a child node within one of my XML
I'm using SimpleXML to load and parse an XML document with PHP. I'm not
I'm using a PHP4 implementation of SimpleXML, which uses the built-in xml_* functions from
I am serializing a class using simple-xml ( http://simple.sourceforge.net/ ) but when i try
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Im attempting to pull in an xml feed that I can load up with

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.