bijukon Posted February 9, 2010 Share Posted February 9, 2010 Hi I've been working on a script that goes through an xml feed that contains property data. I've got most of the property details being collected correctly, however I'm struggling with getting some particulars (such as number of bathroom). The problem for me is that I need to tally up all the bathrooms (type=8) and showerooms (type=13). Some properties don't always have this data, so in such instances I take the number of bedrooms divided by 3 (result being rounded up). The issue I'm getting is that I can't reliably get an accurate number of total bathrooms & Showerrooms, which I can pass out to the main section. The results vary from accurate to quite a bit out especially if a particular type is listed more than once to indicate multiple rooms, as this feed lists rooms varyingly. e.g. type 13 may be listed 2 or 3 times (with number being 1 in each case). any advice appreciated. My code for this section is: foreach($advert->roomsList->room as $rooms) { if ($rooms->type=="1") { $bedrooms=$rooms->number; } if ($rooms->type=="8") { $bathroom=$rooms->number; } if ($rooms->type=="13") { $showerroom=$rooms->number; } } The data is presented as follows <estate id="xxxxxx" type="1"> <reference>286834349</reference> <mandate_num>1810</mandate_num> <mandate_type>1</mandate_type> <roomsList> <room id="3948806" rank="1"> <type>1</type> <comment lang="fr_FR"><![CDATA[]]></comment> <area></area> <number>3</number> <coating></coating> <floor></floor> </room> <room id="3948807" rank="2"> [b]<type>13</type>[/b] <comment lang="fr_FR"><![CDATA[]]></comment> <area></area> [b]<number>1</number>[/b] <coating></coating> <floor></floor> </room> <room id="3948808" rank="3"> [b]<type>13</type>[/b] <comment lang="fr_FR"><![CDATA[]]></comment> <area></area> [b] <number>1</number>[/b] <coating></coating> <floor></floor> </room> <room id="3948809" rank="4"> [b]<type>8</type>[/b] <comment lang="fr_FR"><![CDATA[]]></comment> <area></area> [b]<number>1</number>[/b] <coating></coating> <floor></floor> </room> <room id="3948810" rank="5"> <type>30</type> <comment lang="fr_FR"><![CDATA[]]></comment> <area></area> <number>1</number> <coating></coating> <floor></floor> </room> <room id="3948811" rank="6"> <type>1</type> <comment lang="fr_FR"><![CDATA[]]></comment> <area></area> <number>1</number> <coating></coating> <floor></floor> </room> <room id="3948812" rank="8"> <type>1</type> <comment lang="fr_FR"><![CDATA[]]></comment> <area></area> <number>1</number> <coating></coating> <floor></floor> </room> <room id="3948813" rank="9"> <type>10</type> <comment lang="fr_FR"><![CDATA[]]></comment> <area></area> <number>1</number> <coating></coating> <floor></floor> </room> <room id="3948814" rank="10"> <type>41</type> <comment lang="fr_FR"><![CDATA[]]></comment> <area></area> <number>1</number> <coating></coating> <floor></floor> </room> <room id="3948815" rank="11"> <type>29</type> <comment lang="fr_FR"><![CDATA[]]></comment> <area></area> <number>1</number> <coating></coating> <floor></floor> </room> <room id="3948816" rank="12"> <type>1</type> <comment lang="fr_FR"><![CDATA[]]></comment> <area></area> <number>1</number> <coating></coating> <floor></floor> </room> <room id="3948817" rank="13"> <type>18</type> <comment lang="fr_FR"><![CDATA[]]></comment> <area></area> <number>1</number> <coating></coating> <floor></floor> </room> <room id="3948818" rank="7"> <type>43</type> <comment lang="fr_FR"><![CDATA[]]></comment> <area></area> <number>1</number> <coating></coating> <floor></floor> </room> </roomsList> </estate> Thanks in advance for the help. EDIT: it helps a lot when you put your code in tags Quote Link to comment https://forums.phpfreaks.com/topic/191546-xml-parsing-counting-within-an-entry/ Share on other sites More sharing options...
bijukon Posted February 13, 2010 Author Share Posted February 13, 2010 Hi Would be grateful for a review of the code above, I'm altered the code yet still not getting correct figures. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/191546-xml-parsing-counting-within-an-entry/#findComment-1011718 Share on other sites More sharing options...
Zane Posted February 13, 2010 Share Posted February 13, 2010 have you tried taking the numbers out of quotes; treating them like numbers instead of strings? i.e if ($rooms->type==13) { instead of if ($rooms->type=="13") { Quote Link to comment https://forums.phpfreaks.com/topic/191546-xml-parsing-counting-within-an-entry/#findComment-1011738 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.