XML, PHP return all items

Hi there, new to both XML and PHP so after some time finding myself more and more lost. I’m trying to have all results returned from an XML, at the moment its defaulting to 10. I’d like to know what code I should use and where to place it to return all items in xml. (example xml has only 2)

Here is the PHP code…

<?php

$postUrl = get_permalink($aParams['page_id']);

$mode = isset($aParams['mode']) ? $aParams['mode'] : '';



$aRows = $aSearch = array();

$aSearch = $_POST['search'];




//echo "<pre>"; print_r($aSearch); echo "</pre>";



$xmlFile = "property.xml";



if($mode == "letting")

{

	$searchUrl = $mainApiUrl.'search?sales=false';

}

else

{

	$searchUrl = $mainApiUrl.'search?sales=true';

}


if($aSearch['beds'] > 0)

{

	$searchUrl .= "&beds=".$aSearch['beds'];

}

if($aSearch['minprice'] > 0)

{

	$searchUrl .= "&min=".$aSearch['minprice'];

}

if($aSearch['maxprice'] > 0)

{

	$searchUrl .= "&max=".$aSearch['maxprice'];

}

if($aSearch['ptype'] > 0)

{

	$searchUrl .= "&type=".$aSearch['ptype'];

}

if($aSearch['maxprice'] > 0)

{

	$searchUrl .= "&location=".$aSearch['location'];

}

	

if($aSearch['pricerange'])

{

	$pricerange = explode("-",$aSearch['pricerange']);

	$searchUrl .= "&min=".$pricerange[0];

	if($pricerange[1] > 0)

	{

		$searchUrl .= "&max=".$pricerange[1];

	}

}



//echo $searchUrl;



$aCurl = curl_init($searchUrl);

curl_setopt($aCurl, CURLOPT_RETURNTRANSFER, true);

$curlData = curl_exec($aCurl);



$showResult = 0;


?>

<div id="property-list-wrapper">



<?php



if($curlData)

{

	file_put_contents($xmlFile, $curlData);

	if(file_exists($xmlFile))

	{

		$aRows = simplexml_load_file($xmlFile);


		if($aRows->property)

		{

			$showResult = 2;


			?>

			

			<?php

			foreach($aRows->property as $akey => $aRow)

			{						

				

				$image = plugins_url( 'no_image_thumb.gif', dirname(__FILE__) );

				$propUrl = $postUrl."?property_id=".$aRow->id;

And an example of the xml i’m trying to extract from…

<properties>
 <firstItem>1</firstItem>
 <lastItem>1</lastItem>
 <totalItems>2</totalItems>
 <page>1</page>
 <previousPage>0</previousPage>
 <showNext>true</showNext>
 <nextPage>2</nextPage>
 <searchString></searchString>
 <property>
 <id>1</id>
 <type>Detached</type>
 <bedrooms>1 bedroom</bedrooms>
 <price>195950</price>
 <tenure>Leasehold</tenure>
 <photoID>1</photoID>
 <rentFrequency></rentFrequency>
 <status>Available</status>
 <address>
 <advertising>Palmeira Avenue, Hove, East Sussex, BN3
3NT</advertising>
 <name></name>
 <number>2</number>
 <street>Palmeira Avenue</street>
 <locality></locality>
 <town>Hove</town>
 <county>East Sussex</county>
 <postcode>BN3 3NT</postcode>
 <country>GB</country>
 <latitude>50.826965</latitude>
 <longitude>-0.163236</longitude>
 </address>
 <description>Edwardian property. Recently refurbished
kitchen.</description>
 </property>
</properties>

can anyone even slightly point me in the right direction?

well check me out, i figured it out! I’m better at this than i thought! thanks anyway good people!

So, are you going to update the thread with the solution as well as the question, in case it helps out any future forum user?

Is the PHP code in your first post complete? It seems to terminate in the middle of a foreach() loop.

Yes, sorry, my apologies. Yes is does terminate there as the relevant code was above but wast sure up to that point where to place the solution.

The solution was to add a simple GET parameter…

$searchUrl = $mainApiUrl.'search?items=100';

so…

if($aSearch['pricerange'])

{

	$pricerange = explode("-",$aSearch['pricerange']);

	$searchUrl .= "&min=".$pricerange[0];

	if($pricerange[1] > 0)

	{

		$searchUrl .= "&max=".$pricerange[1];

	}
 
}

 $searchUrl = $mainApiUrl.'search?items=100';

//echo $searchUrl;



$aCurl = curl_init($searchUrl);

curl_setopt($aCurl, CURLOPT_RETURNTRANSFER, true);

$curlData = curl_exec($aCurl);



$showResult = 0;


?>

Sorry about not sharing the solution, i’m a noob here! :wink:

2 Likes

No problem, thanks for coming back to do so.

So not really anything wrong with your code by the look of it, just another parameter for the site you’re accessing.

indeed! :wink:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.