I have a long xml data file with 500+ items in it, it comes in this form:
<?xml version="1.0" encoding="ISO-8859-1"?>
<CATALOG>
<ITEM>
<TITLE>ITEM name</TITLE>
<TYPE>TYPE </TYPE>
<DESCIPTION>DESCIPTIONiliate Page CPM</DESCIPTION>
<PRICE>PRICE</PRICE>
<ITEM>http://mysite.com/item-link</ITEM>
</ITEM>
</CATALOG>
and I use the following code in the php page to import data from the xml file:
<?php
$ITEMSS = new SimpleXMLElement('ITEMS.xml', null, true);
echo <<<EOF
<table width="100%" align="center" border="1" bordercolor="#0099ff" cellpadding="1" cellspacing="0">
<tr>
<th bgcolor="#66ccff"><span class="style4">ITEM Name</span></th>
<th bgcolor="#66ccff"><span class="style4">item TYPE </span></th>
<th bgcolor="#66ccff"><span class="style4">item DESCIPTION </span></th>
<th bgcolor="#66ccff"><span class="style4">item PRICE</span></th>
<th bgcolor="#66ccff"><span class="style4">link to item</span></th>
</tr>
EOF;
foreach($ITEMSS as $ITEMS) // loop through our DATAS
{
echo <<<EOF
<tr height="30" align=middle>
<td><a href="{$ITEMS->ITEM}" target="_blank"><span class="STYLE7">{$ITEMS->TITLE}</span></a></td>
<td><span class="STYLE8">{$ITEMS->TYPE}</span></td>
<td><span class="STYLE8">{$ITEMS->DESCIPTION}</span></td>
<td><span class="STYLE8">{$ITEMS->PRICE}</span></td>
<td><a href="{$ITEMS->ITEM}" target="_blank"><B><span class="STYLE7">cHECK IT OUT</span></B></a></td>
</tr>
EOF;
}
echo '</table>';
?>
I need to add an “if” statement in the loop to select only some data if “TYPE” has a certain value, it will show that data, if not it will skip it.
Also need to add paging system, since there will be 500+ item to be listed, I want the table to show a miximum number of items, saying 25.
Thank you guys for your help!
As an alternative you could select (and process) only those ITEM elements that have a specific text value in the TYPE element via xpath, e.g.
prints
— edit: with some paging functionality —
The function
getData()is just some boilerplate that returns some xml data.For understanding the xpath query have a read of a (good) xpath tutorial, see e.g. Using XPATH to access XML elements (was: Good tutorial to learn xpath)