Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 10-05-2009, 03:04 PM Syntax Question
WebTraffic's Avatar
Extreme Talker

Posts: 225
Name: Brandon
Trades: 0
PHP Code:
<?php
if ($squarefeet == 1500) {
echo 
"<p><img src=\"1500.gif\">";
} if else (
$squarefeet == 2000) {
echo 
"<p><img src=\"2000.gif\">";
} if else (
$squarefeet == 2500) {
echo 
"<p><img src=\"2500.gif\">";
} if else (
$squarefeet == 3000) {
echo 
"<p><img src=\"3000.gif\">";
} if else (
$squarefeet == 3500) {
echo 
"<p><img src=\"3500.gif\">";
} if else (
$squarefeet == 4000) {
echo 
"<p><img src=\"4000.gif\">";
}
?>
Is there something wrong with this code? I keep getting this error:

Parse error: syntax error, unexpected T_ELSE, expecting '(' in /home/ingrams/public_html/system-selector/geothermalcalculator.php on line 11

Line 11 is } if else ($squarefeet == 2000) {

I dont understand why I am getting this error.

Anyone else know why? Is it a problem with the syntax?
__________________

Please login or register to view this content. Registration is FREE

Coding is just like a woman. If you don't do something exactly right, it complains.
WebTraffic is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-05-2009, 03:26 PM Re: Syntax Question
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
All the "if else" should be "else if", or evan "elseif" since php has introduced that keyword aswell. If you want to get rid of some if() statements you could also use switch(). It will do the same thing, some people think it looks better some people don't :P

PHP Code:
switch($squarefeet) {
   case 
1500:
      echo 
"<p><img src=\"1500.gif\">";
      break;
   case 
2000:
      echo 
"<p><img src=\"2000.gif\">";
      break;
   case 
2500:
      echo 
"<p><img src=\"2500.gif\">";
      break;
   case 
3000:
      echo 
"<p><img src=\"3000.gif\">";
      break;
   case 
3500:
      echo 
"<p><img src=\"3500.gif\">";
      break;
   case 
4000:
      echo 
"<p><img src=\"4000.gif\">";
      break;

Or in this case, where the different cases are so similar, you can do like this. Again, it's just a question of which way you like the best, all of them will work.

PHP Code:
$allowed = array(150020002500300035004000);
$size in_array($squarefeet$allowed) ? $squarefeet 1500;
echo 
"<p><img src=\"$size.gif\">"
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 10-05-2009, 03:30 PM Re: Syntax Question
WebTraffic's Avatar
Extreme Talker

Posts: 225
Name: Brandon
Trades: 0
wow i feel stupid lol. my dyslexia kicked in i guess

if else = else if

thank you!
__________________

Please login or register to view this content. Registration is FREE

Coding is just like a woman. If you don't do something exactly right, it complains.
WebTraffic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Syntax Question
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17293 seconds with 12 queries