kawaii1001 Posted August 29, 2013 Share Posted August 29, 2013 (edited) I'm not even sure the correct terminology. I have a foreach loop that contains details about different automobiles. I have another page with a list of automobiles and each one will link to the contents that is pulled from each loop on the details page. How do I make each loop on the details page its own page with a unique id so its not all appearing on one page. This is my loop and I have another page that I want to lead to each of these individually. <?php error_reporting(-1); $preowned = simplexml_load_file('file.xml'); foreach ($preowned as $preownedinfo) { $price = '$' . money_format($preownedinfo->Price, 2); $photosHTML = ''; foreach ($preownedinfo->AditionalPhotos->AditionalPhoto as $addphoto) { $photosHTML .= "<li style=\"float:left; margin:0 2px;\"><img src=\"$addphoto\" width=\"96\" /></li>"; } echo " <div class=\"detailsTitle\"> <a href=\"#\">{$preownedinfo->Yrs} {$preownedinfo->Make} {$preownedinfo->Model} {$preownedinfo->ExtraField->ContentEN->ExteriorColor} {$preownedinfo->ExtraField->ContentEN->Doors} Doors</a> </div> <div> <div style=\"text-align:center\"><img src=\"{$preownedinfo->MainPhoto}\"width=\"400\" border=\"0\" /></div> <div style=\"margin-top:10px;\"> <ul style=\"list-style:none; display:inline;\">$photosHTML</ul> </div> <div style=\"clear:both;\"></div> <div class=\"specsDetails\"> <div class=\"specsDetailsRow\"> <div class=\"leftDetailsSpec\">Our Price: </div> <div class=\"rightSpec\">{$price}</div> </div> <div class=\"specsDetailsRow\"> <div class=\"leftDetailsSpec\">Body Style: </div> <div class=\"rightSpec\">{$preownedinfo->Trim}</div> </div> <div class=\"specsDetailsRow\"> <div class=\"leftDetailsSpec\">Status: </div> <div class=\"rightSpec\">Used</div> </div> <div class=\"specsDetailsRow\"> <div class=\"leftDetailsSpec\">Engine: </div> <div class=\"rightSpec\">{$preownedinfo->ExtraField->ContentEN->Engine}</div> </div> <div class=\"specsDetailsRow\"> <div class=\"leftDetailsSpec\">Transmission: </div> <div class=\"rightSpec\">{$preownedinfo->ExtraField->ContentEN->Transmission}</div> </div> <div class=\"specsDetailsRow\"> <div class=\"leftDetailsSpec\">Ext. Colour: </div> <div class=\"rightSpec\">{$preownedinfo->ExtraField->ContentEN->ExteriorColor}</div> </div> <div class=\"specsDetailsRow\"> <div class=\"leftDetailsSpec\">Int. Colour: </div> <div class=\"rightSpec\">{$preownedinfo->ExtraField->ContentEN->InteriorColor}</div> </div> <div class=\"specsDetailsRow\"> <div class=\"leftDetailsSpec\">Klometres: </div> <div class=\"rightSpec\">{$preownedinfo->ExtraField->ContentEN->Odometer}</div> </div> <div class=\"specsDetailsRow\"> <div class=\"leftDetailsSpec\">Stock Number: </div> <div class=\"rightSpec\">{$preownedinfo->StockNumber}</div> </div> </div> <div class=\"detailsOverview\">{$preownedinfo->AdDescription}</div> <div class=\"detailsOverview requestInfo\"> <a href=\"#\">Request Info</a> </div> </div>"; } ?> Edited August 29, 2013 by kawaii1001 Quote Link to comment Share on other sites More sharing options...
kawaii1001 Posted August 30, 2013 Author Share Posted August 30, 2013 Anybody? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted August 31, 2013 Share Posted August 31, 2013 xml is intended as a data exchange format between different systems, not a database. if your xml data doesn't already have a unique way of identifying each different block of data (or the .xml file will never change, which is unlikely), you would need to alter your xml data format to add a unique identifier to each block of data.this will be a much simpler task, taking less code and effort on your part, and run much faster, if you store this data in a database so that you can let the database assign and manage a unique id for each different piece of data. Quote Link to comment Share on other sites More sharing options...
kawaii1001 Posted September 1, 2013 Author Share Posted September 1, 2013 (edited) Each block in the xml file does actually have an ID. For example: <root> <AD> <ADID displayName="ADID">11230394</ADID> <CompanyID displayName="CompanyID">1235343</CompanyID> <CompanyName displayName="CompanyName">Their name</CompanyName> <Category displayName="Category">Sport Utility</Category> <StockNumber displayName="StockNumber">j00645</StockNumber> <Vin displayName="Vin">3335</Vin> <Status displayName="Status">Used</Status> <Yrs displayName="Year">2009</Yrs> <Make displayName="Make">Lincoln</Make> <Model displayName="Model">Navigator</Model> <Trim displayName="Trim">Sport Utility 4D</Trim>... So the ADID would be the ID for each block. Does this help... Edited September 1, 2013 by kawaii1001 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 1, 2013 Share Posted September 1, 2013 Does this help... i don't know, did it help you when you tried to produce the links with the ADID values in them and to find just the data in the .xml file that matches the submitted ADID value? if you identified that your data has a usable value in it, that's just the first step. the next step would be to actually try to solve this yourself. the other forum members here are not the ones who are trying/need to do this, you are. Quote Link to comment Share on other sites More sharing options...
kawaii1001 Posted September 1, 2013 Author Share Posted September 1, 2013 I'm sorry. I'm just so lost. I really am just trying to figure out php. I was assigned this task and I'm just not even sure the terminology to google. I know that identifier is in the xml file, but even if I set up a link to grab using that, it wouldn't get all of the information in that loop. I was just provided the xml. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 2, 2013 Share Posted September 2, 2013 (edited) the only loop you would (should) have is the one looping over the data to build the links. to find/retrieve the matching element in the xml data, you would use an xpath query to search for it - $preowned = simplexml_load_file('file.xml'); $ADID = isset($_GET['ADID']) ? $_GET['ADID'] : false; // the ADID to search for // test if there is a search term if(!$ADID){ echo 'No search specified'; } else { // search for the element with the given ADID value $result = $preowned->xpath("/root/AD[ADID=$ADID]"); if(empty($result)){ echo 'Not found'; } else { $preownedinfo = $result[0]; // get the first (only) element // display the information from the element that matched the ADID search } } Edited September 2, 2013 by mac_gyver Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.