Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a separate page from a loop

    Would anybody be able to assist. I am at a loss. I am trying to figure out php while trying to parse an xml file. I have to create listings of automobiles. The loop I created to parse the details for each automobile needs to show on its own page. I have figured out I am to use the $_GET function, but I am not sure how to make that loop its own page. It right now shows as one listing after the other on the page. Here is a sample of the info for one automobile on the xml file:
    Code:
     <AD>
     <ADID displayName="ADID">10456241</ADID>
     <CompanyID displayName="CompanyID">41382</CompanyID>
     <CompanyName displayName="CompanyName">GName</CompanyName>
     <Category displayName="Category">Sport Utility</Category>
     <StockNumber displayName="StockNumber">j08669</StockNumber>
     </AD>
    I am assuming the ADID would identify each loop. Here is a sample from my loop:
    Code:
      <?php
      
      $preowned = simplexml_load_file('file.xml');
      foreach ($preowned as $preownedinfo)
           echo "
     <div class=\"detailsTitle\">
         <a href=\"#\">{$preownedinfo->Yrs} {$preownedinfo->Make} {$preownedinfo->Model} {$preownedinfo->ExtraField->ContentEN->ExteriorColor} {$preownedinfo->ExtraField->ContentEN->Doors} Doors</a>
     </div>";
     
     }
     
     ?>
    So, I need this loop to be created as its own page and I will link to it from another page.
    I just am unsure at this point as to what I should even google. Any help would be greatly appreciated!!

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    722
    Thanks
    20
    Thanked 84 Times in 84 Posts
    using a get filter:

    if your page was called xml.php:

    browse to
    PHP Code:
    xml.php?id=10456241 
    contents of xml.php:
    PHP Code:
    <?php
    $page 
    $_GET['id'];
    $xml=simplexml_load_file('file.xml');

    $nodes $xml->xpath("//AD[contains(ADID, $page)]");
    foreach(
    $nodes as $node)
    {
        foreach(
    $node as $name => $prop) {
            
    printf("%s: %s\n"$name$prop);
        }
        echo 
    "\n";
    }
    ?>
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •