Jump to content

Else if statment breaking?


Recommended Posts

Hi everyone, this code keeps breaking my page, Can I pick anybodies brains to see if they can see the error?

 

  <?php 
if(@$row_getdets['travelrad'] == 1):
    echo "locally";
elseif(@$row_getdets['travelrad'] == 2): 
    echo "Anywhere in the UK";
elseif(@$row_getdets['travelrad'] == 3): 
    echo "Worldwide";
else:
    
endif;

?>

Link to comment
https://forums.phpfreaks.com/topic/202057-else-if-statment-breaking/
Share on other sites

Your suppressing any errors by using the "@". Remove it while debugging.

 

A better way of doing this (IMHO) would be:

<?php
$dest = array('','locally','anywhere in the UK','Worldwide');
if ($row_getdets['travelrad'] > 0 && $row_getdets['travelrad'] < 4) {
   echo $dest[$row_getdets['travelrad']];
}
?>

 

Ken

Ive jsut tried altering it so I can use it on another variable I have and it isnt working, im unsure what the funtions called but does this seem valid?

 <?php 
  $workcon = array('','Portrait','Catwalk','Glamour','Implied Topless','Implied Nude','Glamour Topless','Glamour Nude', 'Promotions','Other');
if ($row_getdets['workconsidered'] > 0 && $row_getdets['workconsidered'] < 10) {
   echo $workcon[$row_getdets['workconsidered']];?>

The only problem I'm seeing in your code is that you don't close the "if" block with a "}".

 

One change I would make to my original "if" would be to count($array) in the second condition:

<?php
if ($row_getdets['workconsidered'] > 0 && $row_getdets['workconsidered'] < count($workcon)) {
   echo $workcon[$row_getdets['workconsidered']];
   }
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.