The Ace Posted May 29, 2008 Posted May 29, 2008 This is probably really easy, but I just can't find out how to work it: I would like it so that when a person attempts to buy a house they can't afford, it says how much more money they need to get the house....I have this: {$np['hPRICE']} - {$ir['money']} But that only outputs the house price minus the users money...but not the final answer. This also doesn't work: ({$np['hPRICE']} - {$ir['money']}) I thought I would need the ( and ), but no.... Can anyone help me...please. :-P Cheers, The Ace Quote
Decepti0n Posted May 29, 2008 Posted May 29, 2008 Re: Slight Problem What? House price: 100 User money: 80 100 - 80 = 20 ~ how much more they need How isn't that right? Unless you mean it just shows "You need 100 - 80", then do it outside of the string: $need = number_format($np['hPRICE'] - $ir['money']); echo 'You need $' . $need . ' to buy the house'; Quote
The Ace Posted May 29, 2008 Author Posted May 29, 2008 Re: Slight Problem Grr...I get this: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /usr/home/*****/domains/***/public_html/newestate2.php on line 17 Here are my lines above and below the parse error: else if ($np['hPRICE'] > $ir['money']) { print "You do not have enough money to buy the {$np['hNAME']} for £{$np['hPRICE']}. $need = number_format($np['hPRICE'] - $ir['money']); echo 'You need £' . $need . ' more to buy this house.'"; This is line 17: $need = number_format($np['hPRICE'] - $ir['money']); Thanks for helping me! Unless you mean it just shows "You need 100 - 80", Yes...I did mean that! :-P lol. Quote
Decepti0n Posted May 29, 2008 Posted May 29, 2008 Re: Slight Problem else if ($np['hPRICE'] > $ir['money']) { print "You do not have enough money to buy the {$np['hNAME']} for £{$np['hPRICE']}"; $need = number_format($np['hPRICE'] - $ir['money']); echo 'You need £' . $need . ' more to buy this house.'; You have to remember/learn where strings break, what is a string, what a string can do/contain, how its parsed Quote
The Ace Posted May 29, 2008 Author Posted May 29, 2008 Re: Slight Problem Thank you very much! Works perfectly! How do I get this: You do not have enough money to buy the White Hole for £1.5e+10. You need £14,999,800,000 more to buy this house. to display: £15,000,000,000? Do I add a number_format after the £ sign and before {$np['hPRICE']}. "; Thanks again! :D Quote
Decepti0n Posted May 29, 2008 Posted May 29, 2008 Re: Slight Problem Yeah, but you'll have to split up the string and concatenate it. Trust me it'll be better in the long run if I don't just hand it to you Quote
The Ace Posted May 29, 2008 Author Posted May 29, 2008 Re: Slight Problem Yeah...good point. I'll have a go myself. Thanks. Quote
The Ace Posted May 30, 2008 Author Posted May 30, 2008 Re: Slight Problem Yay! I did it myself...I just used another "need" function, but called it $need2! Thanks Deception! :) Quote
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.