PHP If Statement

Hi,

I am struggling with some PHP code that i need to put into place to remove the "Not Applicable" part on the following page:

http://www.central-estates.co.uk/walthamstow-property-to-rent

This is the script that displays the Title of each property which includes this "Not applicable" text

<h1><?php echo $xml['PROPERTIES'][0]['PROPERTY'][$i]['SA1'][0]['VALUE']; ?>, <?php echo $xml['PROPERTIES'][0]['PROPERTY'][$i]['PC'][0]['VALUE']; ?> (<?php echo return_status_text($details['PROPERTY'][0]['ATTRIBUTES']['LEASE']); ?>)</h1>

I was told to include an if statement to only display the lease type based on what data was entered, so if nothing was entered then not to display the lease type in the title. The following was what i was advised to use but im not sure what i need to be calling:

If (leasetype =”not applicable”)
{
}
Else{
Display lease type
}

I have attached the files that are used for the property search and rental search.

Hope you can help

Thanks,
property-details.php
property-search.php
Andy6350Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Andy6350Author Commented:
This maybe of some help:

property/@leaseType
XML attribute
int
The lease type of the property, possible values are:

1 = Not Applicable
3 = Freehold
5 = Freehold (to be confirmed)
2 = Leasehold
4 = Leasehold (to be confirmed)
6 = To be Advised
7 = Share of Leasehold
8 = Share of Freehold
9 = Flying Freehold
11 = Leasehold (Share of Freehold)
0
Ray PaseurCommented:
Since it looks like you're new to programming in general and PHP in particular, please read this article to find your way to some good learning resources that will help you get a foundation in this stuff.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

If you can please post some of the test data we can show you how to parse it.  We do not need to see the program code that doesn't work - just the input data and an example of what you want to get out of it.
0
John EastonDirectorCommented:
I'm fairly new to PHP, but have used ASP for a while.  Personally just to remove a bit of text I would use str_replace.  It should look something like this:
<h1><?php echo $xml['PROPERTIES'][0]['PROPERTY'][$i]['SA1'][0]['VALUE']; ?>, <?php echo $xml['PROPERTIES'][0]['PROPERTY'][$i]['PC'][0]['VALUE']; ?> (<?php echo str_replace('(Not Applicable','',return_status_text($details['PROPERTY'][0]['ATTRIBUTES']['LEASE'])); ?>)</h1>

Open in new window


This looks for the text 'Not applicable' and replces it with nothing.  Please note, if the 'not applicable' text changes (i.e. you change it to n/a in the database) then you need to change this bit of code too.

Otherwise you want an if statement which checks if $details['PROPERTY'][0]['ATTRIBUTES']['LEASE']) != 1 Then output text.  I.e. don't output if it is 1.

Hope this helps.
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Andy6350Author Commented:
Thanks for that. I probably would prefer to use an if statement, would you happen to know the whole script i would need to use?

Thanks,
0
Ray PaseurCommented:
If you can please post some of the test data we can show you how to parse it...
0
John EastonDirectorCommented:
You can do it in a couple of ways, but personally I would create a new variable, set it through the if statement and then pass the new variable to be output.

So:
<h1><?php echo $xml['PROPERTIES'][0]['PROPERTY'][$i]['SA1'][0]['VALUE']; ?>, <?php echo $xml['PROPERTIES'][0]['PROPERTY'][$i]['PC'][0]['VALUE']; ?> (
<?php
if ($details['PROPERTY'][0]['ATTRIBUTES']['LEASE'] != 1)
   $statustext = return_status_text($details['PROPERTY'][0]['ATTRIBUTES']['LEASE']);
echo $statustext;
?>)
</h1>

Open in new window


As I said before, I am new to PHP so some of the syntax may be incorrect.  But I think if you replace your line with the above I should do what you want.

Also, I have made an assumption that $details['PROPERTY'][0]['ATTRIBUTES']['LEASE'] contains the int values and the function return_status_text translates that into the text.  If those assumptions are wrong the above may have unexpected results!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
@JEaston: With a background in ASP, you could get up to speed on PHP in a month or so.  This is where I would start (get the latest edition).
http://www.amazon.com/PHP-MySQL-Web-Development-Edition/dp/0321833899

@Andy6350: This will help to explain why we need you to post the test data.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_7830-A-Quick-Tour-of-Test-Driven-Development.html
0
Slick812Commented:
greetings Andy6350, I really wish you had given us some information in your question about the IMPORTANT code section that you need to work on, this example you gave -
If (leasetype =”not applicable”)
{
}
Else{
Display lease type
}

was absolutely NO HELP at all to me, when I was looking at your code in your attached PHP files, you also failed to mention that the -
property/@leaseType
was NO WHERE in your code, and for me a blind reference, I am NOT a mind reader!
However, I looked at the result page on -
http://www.central-estates.co.uk/walthamstow-property-to-rent
Looked at the page source for  "not applicable" and then some code text searches for "<h1" and found this line -
<h1><?php echo $xml['PROPERTIES'][0]['PROPERTY'][$i]['SA1'][0]['VALUE']; ?>, <?php echo $xml['PROPERTIES'][0]['PROPERTY'][$i]['PC'][0]['VALUE']; ?> (<?php echo return_status_text($details['PROPERTY'][0]['ATTRIBUTES']['LEASE']); ?>)</h1>

which is what you posted, but I had NO IDEA the arrangement or content of these XML array elements! , sorry I'm so dumb,
However, it seems that this "property/@leaseType" of yours is extracted OUT with -
return_status_text($details['PROPERTY'][0]['ATTRIBUTES']['LEASE']);

any how, here is something that may or may not help you on the elimination of the text "not applicable"-
<?php $status = return_status_text($details['PROPERTY'][0]['ATTRIBUTES']['LEASE']); 
 if ($status == 'not applicable') $status= ''; else $status = ' ('.$status.')';
 ?>
<h1><?php echo $xml['PROPERTIES'][0]['PROPERTY'][$i]['SA1'][0]['VALUE'].', '.$xml['PROPERTIES'][0]['PROPERTY'][$i]['PC'][0]['VALUE'].$status; ?></h1>

Open in new window

This leaves out the two ( ) along with the 'not applicable', , which may or may not be what you want to do. this is untested, but should give you an Idea of what to try and do, your (to me) simple if test, does not seem to be complex at all, compared to the rather complex if code you have for all of the XML access like -
if($xml['PROPERTY'][0]['TEXT'][0]['AREA'][0]['FEATURE'][$i]['HEADING'][0]['VALUE'] != '' and $xml['PROPERTY'][0]['TEXT'][0]['AREA'][0]['FEATURE'][$i]['PARA'][0]['VALUE'] != '') {

so I can not see that you are unable to figure this yourself?
ask questions if you need more info. .
0
Andy6350Author Commented:
Hi,

This has been put on hold until i get the correct file structure from the developer of the website. However i didn't have much knowledge of this hence why i asked for help, but on several occasions i got a rude response which i was shocked with. I thought this was a site where non experts like myself could seek advice from experts?
0
Ray PaseurCommented:
Of course it is!  All we really need is to see your test data and to see what result you want to get out of the process.  Armed with that, we can almost always give you a good answer.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.