How to create page with php loop

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:

<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

error_reporting(-1);

$preowned = simplexml_load_file(‘file.xml’);
foreach ($preowned as $preownedinfo)
{
$price = ‘$’ . money_format($preownedinfo->Price, 2, ‘.’, ‘,’);

$photosHTML = '';
foreach ($preownedinfo->AditionalPhoto as $addphoto)
{
    $photosHTML .= "<li>$addphoto</li>";
}

echo "
{$preownedinfo->Yrs} {$preownedinfo->Make} {$preownedinfo->Model} {$preownedinfo->ExtraField->ContentEN->ExteriorColor} {$preownedinfo->ExtraField->ContentEN->Doors} Doors
";

}

?> [/code]

I just am unsure at this point as to what I should even google. Any help would be greatly appreciated!!

If you want to stay on that XML file you would i.e have one php script only building the catalog

let’s call it catalog.php

and you would have another one that is only extracting data of a single car.

let’s call it car.php

I assume that ADID is unique throughout your XML and can be used as an identifier.

In catalog.php you are not showing all the details.
You are only building a link menu for each car in the XML like this:
https://example com/car.php?adid=10456241
As label you can use some of the car info like the type and age maybe, or whatever suits you.

In car.php you are looping through the XML, but discarding all datasets that do not match $_GET[‘adid’]

The value given in the url parameter ?adid=10456241 will be in that variable.

So in your loop you could simply add a line like this
if ($adid_from_xml != $_GET[‘adid’]) continue;

continue in a loop will skip what follows and dorectly jump to the next iteration.

So it will just skip unless the adid is the wanted one.
So you can print your listing.

The concept is not to create a bunch of listings all at once, but to create the selected one listing always on demand.

Please don’t use the code as is. It is meant for illustration only and is insecure, because the $_GET parameter should not be trusted and checked before using, because ofc you could manually throw in whatever you want there.

@reddig.hamburg , please don’t reply to threads that are over a decade old. This thread was bumped by @spring, deleting his/her own reply.

Thread closed.

Sponsor our Newsletter | Privacy Policy | Terms of Service